2019.01.22 15:11 "[Tiff] Possible bug in libTiff 4.0.9?", by SM

2019.01.22 15:11 "[Tiff] Possible bug in libTiff 4.0.9?", by SM


I have upgraded to TIFF 4.0.9 from 4.0.0 and I saw the following change in tif_write.c:


which fixes tif_encodestrip() and it returns -1 in case of failure as documented.

I believe this fix might have uncovered another bug in the library. I came across a special case while writing a YCbCr image which is JPEG compressed and contains a partial strip. The last strip could not be encoded successfully. I found that the failure is occurring in jpeg_write_raw_data in the JPEG library. It seems that the cinfo structure passed to the JPEG library from TIFF library contains incorrect dimensions of the strip if it is partial.

The buffer that is being passed to the library is of the same size as the whole strip (even in the case of a partial strip). In case of a partial strip, the rest of the buffer is filled with zeros.

Image details to be written:

'ImageWidth' - 3008

‘ImageLength’ - 1952

'Photometric' - YCbCr

'Compression' - JPEG

'BitsPerSample' - 8

'SamplesPerPixel' - 3

‘SampleFormat', - UInt

'PlanarConfiguration' - Chunky

'RowsPerStrip' - 256

'YCbCrSubSampling' - [2 1]

Can you please confirm if it is a bug?