tags:

views:

99

answers:

1

If I try to open an invalid TIFF file with TIFFOpen(), the function returns NULL. For some reason, the error handler isn't called. However, the file remains open, so I can't delete/overwrite it from the same process.

I tried using TIFFFdOpen(), so that I can close the handle myself, but for some reason it gives me this error on valid TIFFs: "Cannot read TIFF header". This time the error is passed via the error handler.

How can I solve either of these problems?

Update: I'm talking about problems in TIFFOpen() itself, not in functions called later on. For example, they might occur if the TIFF file has size zero.

A: 

Perhaps you have an old or broken libtiff? I tried with libtiff-3.8.2 and it seems to work OK:

$ head -c 1000000 sample.tif > broken.tif
$ tiffinfo broken.tif
TIFFReadDirectory: broken.tif: Can not read TIFF directory count.
$ strace tiffinfo broken.tif 
...
open("broken.tif", O_RDONLY)            = 3
...
write(2, "broken.tif: Can not read TIFF dir"...
...
close(3)                                = 0
exit_group(0)                           = ?

Ie. there's a sane error and no leak (explicit close before the exit). I get the same behaviour with my own code.

jrgc
Good point. I have 3.7.3But anyway, maybe this error is not in TIFFOpen(). What happens with a zero-sized file?
Lev