1999.10.04 17:05 "libtiff problems with Group 4", by Joel Schumacher

1999.10.05 09:13 "Re: libtiff problems with Group 4", by Frank D. Cringle

I turned on DEBUG mode and recompiled tiffinfo to get it to show exactly what it's decoding, then ran it with the -D option on a problem file:

0000001F/9: V0         0        1
0000000F/8: V0         0        1
00000007/7: V0         0        1
00002003/14: V0         0       1
00001001/13: V0         0       1
00000800/12: EOL        0       0000000
Fax4Decode: 169439.tif: Bad code word at scanline 3291 (x 0).
Fax4Decode: Warning, 169439.tif: Premature EOL at scanline 3291 (got 0, expected 2544).

This seems to be a bug that was fixed in viewfax after the code was incorporated into libtiff. Here's a patch. Unfortunately, it is entirely untested, due to lack of time on my part. Give it a try...

================================================================
diff -uNr tiff-v3.4/libtiff/tif_fax3.c tiff-v3.4.new/libtiff/tif_fax3.c
--- tiff-v3.4/libtiff/tif_fax3.c Tue Apr 30 00:16:27 1996
+++ tiff-v3.4.new/libtiff/tif_fax3.c    Tue Oct  5 11:04:20 1999
@@ -1382,6 +1382,12 @@
                  tif->tif_row++;
                 continue;
       EOFG4:
+         NeedBits(13);
+#ifdef FAX3_DEBUG
+                if (GetBits(13) != 0x1001)
+               fputs("Bad RTC\n", stderr);
+#endif
+           ClrBits(13);
            (*sp->fill)(buf, thisrun, pa, lastx);
           UNCACHE_STATE(tif, sp);
                 return (-1);
diff -uNr tiff-v3.4/libtiff/tif_fax3.h tiff-v3.4.new/libtiff/tif_fax3.h
--- tiff-v3.4/libtiff/tif_fax3.h     Tue Apr 30 00:16:28 1996
+++ tiff-v3.4.new/libtiff/tif_fax3.h    Tue Oct  5 11:05:07 1999
@@ -485,9 +485,10 @@
        goto eol2d;                                                 \
       case S_EOL:                                                     \
           *pa++ = lastx - a0;                                         \
-          NeedBits8(5,eof2d);                                         \
-          if (GetBits(5))                                             \
+          NeedBits8(4,eof2d);                                         \
+          if (GetBits(4))                                             \
               unexpected("EOL", a0);                                  \
+          ClrBits(4);                                                 \
           EOLcnt = 1;                                                 \
           goto eol2d;                                                 \
       default:                                                        \

Frank Cringle,      fdc@cliwe.ping.de
voice: (+49 2304) 467101; fax: 943357