2004.10.10 07:30 "[Tiff] libtiff 3.7.0 beta 2", by Steve Underwood

2004.10.12 14:00 "Re: [Tiff] libtiff 3.7.0 beta 2", by Dmitry V. Levin

Hi,

libtiff 3.7.0 beta 2 seems unable to generate TIFF files of FAX images reliably. When I try to generate a T.4 2D compressed file I get:

    Integer overflow in TIFFVTileSize

This is known issue, attached patch should fix the problem, please test it.

ldv

Index: libtiff/tif_dirread.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dirread.c,v
retrieving revision 1.42
diff -u -p -r1.42 tif_dirread.c
--- libtiff/tif_dirread.c       29 Sep 2004 07:42:52 -0000      1.42
+++ libtiff/tif_dirread.c       12 Oct 2004 12:41:06 -0000
@@ -644,19 +644,29 @@ TIFFReadDirectory(TIFF* tif)
        tif->tif_curstrip = (tstrip_t) -1;
        tif->tif_col = (uint32) -1;
        tif->tif_curtile = (ttile_t) -1;
-       tif->tif_tilesize = TIFFTileSize(tif);
-       tif->tif_scanlinesize = TIFFScanlineSize(tif);
+       tif->tif_tilesize = (tsize_t) -1;

-       if (!tif->tif_tilesize) {
-               TIFFError(module, "%s: cannot handle zero tile size",
-                         tif->tif_name);
-               return (0);
-       }
+       tif->tif_scanlinesize = TIFFScanlineSize(tif);
        if (!tif->tif_scanlinesize) {
                TIFFError(module, "%s: cannot handle zero scanline size",
                          tif->tif_name);
                return (0);
        }
+
+       if (isTiled(tif)) {
+               tif->tif_tilesize = TIFFTileSize(tif);
+               if (!tif->tif_tilesize) {
+                       TIFFError(module, "%s: cannot handle zero tile size",
+                                 tif->tif_name);
+                       return (0);
+               }
+       } else {
+               if (!TIFFStripSize(tif)) {
+                       TIFFError(module, "%s: cannot handle zero strip size",
+                                 tif->tif_name);
+                       return (0);
+               }
+       }
        return (1);
 bad:
        if (dir)
Index: libtiff/tif_jpeg.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_jpeg.c,v
retrieving revision 1.23
diff -u -p -r1.23 tif_jpeg.c
--- libtiff/tif_jpeg.c  2 Oct 2004 13:29:41 -0000       1.23
+++ libtiff/tif_jpeg.c  12 Oct 2004 12:41:06 -0000
@@ -1396,7 +1396,7 @@ JPEGVSetField(TIFF* tif, ttag_t tag, va_
                 * Must recalculate cached tile size
                 * in case sampling state changed.
                 */
-               tif->tif_tilesize = TIFFTileSize(tif);
+               tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
                return (1);                     /* pseudo tag */
        case TIFFTAG_JPEGTABLESMODE:
                sp->jpegtablesmode = va_arg(ap, int);
Index: libtiff/tif_luv.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_luv.c,v
retrieving revision 1.12
diff -u -p -r1.12 tif_luv.c
--- libtiff/tif_luv.c   2 Oct 2004 13:29:41 -0000       1.12
+++ libtiff/tif_luv.c   12 Oct 2004 12:41:06 -0000
@@ -1509,7 +1509,7 @@ LogLuvVSetField(TIFF* tif, ttag_t tag, v
                /*
                 * Must recalculate sizes should bits/sample change.
                 */
-               tif->tif_tilesize = TIFFTileSize(tif);
+               tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
                tif->tif_scanlinesize = TIFFScanlineSize(tif);
                return (1);
        case TIFFTAG_SGILOGENCODE:
Index: libtiff/tif_ojpeg.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_ojpeg.c,v
retrieving revision 1.13
diff -u -p -r1.13 tif_ojpeg.c
--- libtiff/tif_ojpeg.c 14 Sep 2004 06:32:19 -0000      1.13
+++ libtiff/tif_ojpeg.c 12 Oct 2004 12:41:06 -0000
@@ -2301,7 +2301,7 @@ OJPEGVSetField(register TIFF *tif,ttag_t

           if ((tif->tif_flags ^ v32) & TIFF_UPSAMPLED)
             {
-              tif->tif_tilesize = TIFFTileSize(tif);
+              tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
               tif->tif_flags |= TIFF_DIRTYDIRECT;
             };
           return 1;
Index: libtiff/tif_pixarlog.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_pixarlog.c,v
retrieving revision 1.7
diff -u -p -r1.7 tif_pixarlog.c
--- libtiff/tif_pixarlog.c      2 Oct 2004 13:29:41 -0000       1.7
+++ libtiff/tif_pixarlog.c      12 Oct 2004 12:41:06 -0000
@@ -1232,7 +1232,7 @@ PixarLogVSetField(TIFF* tif, ttag_t tag,
        /*
         * Must recalculate sizes should bits/sample change.
         */
-       tif->tif_tilesize = TIFFTileSize(tif);
+       tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
        result = 1;             /* NB: pseudo tag */
        break;
Index: libtiff/tif_write.c
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tif_write.c,v
retrieving revision 1.15
diff -u -p -r1.15 tif_write.c
--- libtiff/tif_write.c 2 Oct 2004 13:29:41 -0000       1.15
+++ libtiff/tif_write.c 12 Oct 2004 12:41:06 -0000
@@ -528,7 +528,7 @@ TIFFWriteCheck(TIFF* tif, int tiles, con
                    tif->tif_name, isTiled(tif) ? "tile" : "strip");
                return (0);
        }
-       tif->tif_tilesize = TIFFTileSize(tif);
+       tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
        tif->tif_scanlinesize = TIFFScanlineSize(tif);
        tif->tif_flags |= TIFF_BEENWRITING;
        return (1);