[Gdal-dev] Use of assert() on troublesome files

Ben Discoe ben at vterrain.org
Thu Mar 4 22:00:49 EST 2004


This evening i was trying to read a TIF file from a data agency, here:

ftp://keone.soest.hawaii.edu/pub/coastal_ftp/Imagery/Oahu/GeoTiffs/kaenapt.z
ip

It crashes GDAL (assert failure) down inside the TIF code.  This got me
thinking, why do we use assert() this way in GDAL?  It effectively crashes
the calling app, which then has no way to inform the user of the problem or
continue gracefully.

It was fixable by changing the assert:

fmts/gtiff/libtiff.c, line 606
< 	assert(sp->cinfo.comm.is_decompressor);
----
> 	if (sp->cinfo.comm.is_decompressor == 0) {
>		TIFFError("JPEGSetupDecode", "JPEG is not decompressor");
>		return (0);
>	}

1. Perhaps there is some way to trap these assert() failures in an app
calling GDAL?
2. Perhaps assert() should be used only to detect cases of a logical flaw in
the code, rather than unexpected input data?

Thanks,
Ben




More information about the Gdal-dev mailing list