2015.05.08 17:51 "[Tiff] Long standing bug in LibTIFF LZW compression", by Andy Cave

2015.05.08 17:51 "[Tiff] Long standing bug in LibTIFF LZW compression", by Andy Cave

Dear All,

There is a longstanding bug in the LZW decompressor in LibTIFF. It fails to decode files that contain two consecutive CODE_CLEAR codes. These are allowed by the LZW spec and the same data sequence is correctly decoded by Acrobat if you wrap the data in a PDF file.

The fix is simple:

  1. Add "do {" after the line "if (code == CODE_CLEAR) {" in both LZWDecode and LZWDecodeCompat.
  2. Add "} while (code == CODE_CLEAR);" before the line " if (code == CODE_EOI)" (half a dozen lines or so down from the first change) in both LZWDecode and LZWDecodeCompat.
  3. I have no idea how to submit a diff of the fix or fix the public domain source, so if someone could help who knows how to, it should do no harm to fix the bug.

Regards,

Andy.