tools/tiffcp.c:1341: error: Integer Overflow L2
  ([0, max(0, `in->tif_dir.td_tilelength`)] - 1):unsigned32 by call to `TIFFReadTile`.

tools/tiffcp.c:1315:1: Parameter `in->tif_dir.td_tilelength`
1313. }
1314. 
1315. DECLAREreadFunc(readContigTilesIntoBuffer)
      ^
1316. {
1317. 	int status = 1;

tools/tiffcp.c:1318:21: Call
1316. {
1317. 	int status = 1;
1318. 	tsize_t tilesize = TIFFTileSize(in);
                          ^
1319. 	tdata_t tilebuf;
1320. 	uint32 imagew = TIFFScanlineSize(in);

libtiff/tif_tile.c:272:1: Parameter `tif->tif_dir.td_tilelength`
  270. 	return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));
  271. }
  272. tmsize_t
       ^
  273. TIFFTileSize(TIFF* tif)
  274. {

libtiff/tif_tile.c:278:4: Call
  276. 	uint64 m;
  277. 	tmsize_t n;
  278. 	m=TIFFTileSize64(tif);
          ^
  279. 	n=(tmsize_t)m;
  280. 	if ((uint64)n!=m)

libtiff/tif_tile.c:267:1: Parameter `tif->tif_dir.td_tilelength`
    265.  * Compute the # bytes in a row-aligned tile.
    266.  */
    267. uint64
         ^
    268. TIFFTileSize64(TIFF* tif)
    269. {

libtiff/tif_tile.c:270:10: Call
    268. TIFFTileSize64(TIFF* tif)
    269. {
    270. 	return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));
                  ^
    271. }
    272. tmsize_t

libtiff/tif_tile.c:200:1: Parameter `tif->tif_dir.td_tilelength`
      198.  * Compute the # bytes in a variable length, row-aligned tile.
      199.  */
      200. uint64
           ^
      201. TIFFVTileSize64(TIFF* tif, uint32 nrows)
      202. {

tools/tiffcp.c:1321:18: Call
1319. 	tdata_t tilebuf;
1320. 	uint32 imagew = TIFFScanlineSize(in);
1321. 	uint32 tilew  = TIFFTileRowSize(in);
                       ^
1322. 	int64 iskew = (int64)imagew - (int64)tilew;
1323. 	uint8* bufp = (uint8*) buf;

libtiff/tif_tile.c:181:1: Parameter `tif->tif_dir.td_tilelength`
  179. 	return (tilerowsize);
  180. }
  181. tmsize_t
       ^
  182. TIFFTileRowSize(TIFF* tif)
  183. {

libtiff/tif_tile.c:187:4: Call
  185. 	uint64 m;
  186. 	tmsize_t n;
  187. 	m=TIFFTileRowSize64(tif);
          ^
  188. 	n=(tmsize_t)m;
  189. 	if ((uint64)n!=m)

libtiff/tif_tile.c:143:1: Parameter `tif->tif_dir.td_tilelength`
    141.  * Compute the # bytes in each row of a tile.
    142.  */
    143. uint64
         ^
    144. TIFFTileRowSize64(TIFF* tif)
    145. {

tools/tiffcp.c:1341:8: Call
1339. 
1340. 		for (col = 0; col < imagewidth && colb < imagew; col += tw) {
1341. 			if (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0
             ^
1342. 			    && !ignore) {
1343. 				TIFFError(TIFFFileName(in),

libtiff/tif_read.c:668:1: Parameter `tif->tif_dir.td_tilelength`
  666.  * tile is selected by the (x,y,z,s) coordinates.
  667.  */
  668. tmsize_t
       ^
  669. TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)
  670. {

libtiff/tif_read.c:673:10: Call
  671. 	if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))
  672. 		return ((tmsize_t)(-1));
  673. 	return (TIFFReadEncodedTile(tif,
                ^
  674. 	    TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));
  675. }

libtiff/tif_read.c:681:1: Parameter `tif->tif_dir.td_tilelength`
    679.  * amount into the user-supplied buffer.
    680.  */
    681. tmsize_t
         ^
    682. TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)
    683. {

libtiff/tif_read.c:718:6: Call
    716. 	else if (size > tilesize)
    717. 		size = tilesize;
    718. 	if (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,
              ^
    719. 	    (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {
    720. 		(*tif->tif_postdecode)(tif, (uint8*) buf, size);

libtiff/tif_read.c:842:1: Parameter `tif->tif_dir.td_tilelength`
      840.  * expanded, as necessary, to hold the tile's data.
      841.  */
      842. int
           ^
      843. TIFFFillTile(TIFF* tif, uint32 tile)
      844. {

libtiff/tif_read.c:951:10: Call
      949. 		}
      950. 	}
      951. 	return (TIFFStartTile(tif, tile));
                    ^
      952. }
      953. 

libtiff/tif_read.c:1040:1: <LHS trace>
1038.  * tile has just been read in.
1039.  */
1040. static int
      ^
1041. TIFFStartTile(TIFF* tif, uint32 tile)
1042. {

libtiff/tif_read.c:1040:1: Parameter `tif->tif_dir.td_tilelength`
        1038.  * tile has just been read in.
        1039.  */
        1040. static int
              ^
        1041. TIFFStartTile(TIFF* tif, uint32 tile)
        1042. {

libtiff/tif_read.c:1062:19: Binary operation: ([0, max(0, in->tif_dir.td_tilelength)] - 1):unsigned32 by call to `TIFFReadTile` 
        1060.         }
        1061. 	tif->tif_row = (tile % howmany32) * td->td_tilelength;
        1062.         howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
                                ^
        1063.         if (howmany32 == 0) {
        1064.                 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");

static int
TIFFStartTile(TIFF* tif, uint32 tile)
{
        static const char module[] = "TIFFStartTile";
	TIFFDirectory *td = &tif->tif_dir;
        uint32 howmany32;
        if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)
                return 0;
	if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
		if (!(*tif->tif_setupdecode)(tif))
			return (0);
		tif->tif_flags |= TIFF_CODERSETUP;
	}
	tif->tif_curtile = tile;
        howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);
        if (howmany32 == 0) {
                 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
                return 0;
        }
	tif->tif_row = (tile % howmany32) * td->td_tilelength;
        howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
        if (howmany32 == 0) {
                TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
                return 0;
        }
	tif->tif_col = (tile % howmany32) * td->td_tilewidth;
        tif->tif_flags &= ~TIFF_BUF4WRITE;
	if (tif->tif_flags&TIFF_NOREADRAW)
	{
		tif->tif_rawcp = NULL;
		tif->tif_rawcc = 0;
	}
	else
	{
		tif->tif_rawcp = tif->tif_rawdata;
		tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
	}
	return ((*tif->tif_predecode)(tif,
			(uint16)(tile/td->td_stripsperimage)));
}
['DECLAREreadFunc(readContigTilesIntoBuffer)\n{\n\tint status = 1;\n\ttsize_t tilesize = TIFFTileSize(in);\n\ttdata_t tilebuf;\n\tuint32 imagew = TIFFScanlineSize(in);\n\tuint32 tilew  = TIFFTileRowSize(in);\n\tint64 iskew = (int64)imagew - (int64)tilew;\n\tuint8* bufp = (uint8*) buf;\n\tuint32 tw, tl;\n\tuint32 row;\n\t(void) spp;\n\ttilebuf = _TIFFmalloc(tilesize);\n\tif (tilebuf == 0)\n\t\treturn 0;\n\t_TIFFmemset(tilebuf, 0, tilesize);\n\t(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);\n\t(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);\n\tfor (row = 0; row < imagelength; row += tl) {\n\t\tuint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;\n\t\tuint32 colb = 0;\n\t\tuint32 col;\n\t\tfor (col = 0; col < imagewidth && colb < imagew; col += tw) {\n\t\t\tif (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0\n\t\t\t    && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t    "Error, can\'t read tile at %lu %lu",\n\t\t\t\t    (unsigned long) col,\n\t\t\t\t    (unsigned long) row);\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto done;\n\t\t\t}\n\t\t\tif (colb > iskew) {\n\t\t\t\tuint32 width = imagew - colb;\n\t\t\t\tuint32 oskew = tilew - width;\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t    tilebuf, nrow, width,\n\t\t\t\t    oskew + iskew, oskew );\n\t\t\t} else\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t    tilebuf, nrow, tilew,\n\t\t\t\t    iskew, 0);\n\t\t\tcolb += tilew;\n\t\t}\n\t\tbufp += imagew * nrow;\n\t}\ndone:\n\t_TIFFfree(tilebuf);\n\treturn status;\n}', 'tmsize_t\nTIFFTileSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileSize64(TIFF* tif)\n{\n\treturn (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));\n}', 'uint64\nTIFFVTileSize64(TIFF* tif, uint32 nrows)\n{\n\tstatic const char module[] = "TIFFVTileSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0 ||\n\t    td->td_tiledepth == 0)\n\t\treturn (0);\n\tif ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t    (td->td_photometric==PHOTOMETRIC_YCBCR)&&\n\t    (td->td_samplesperpixel==3)&&\n\t    (!isUpSampled(tif)))\n\t{\n\t\tuint16 ycbcrsubsampling[2];\n\t\tuint16 samplingblock_samples;\n\t\tuint32 samplingblocks_hor;\n\t\tuint32 samplingblocks_ver;\n\t\tuint64 samplingrow_samples;\n\t\tuint64 samplingrow_size;\n\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,\n\t\t    ycbcrsubsampling+1);\n\t\tif ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4)\n\t\t    ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4))\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t     "Invalid YCbCr subsampling (%dx%d)",\n\t\t\t\t     ycbcrsubsampling[0],\n\t\t\t\t     ycbcrsubsampling[1] );\n\t\t\treturn 0;\n\t\t}\n\t\tsamplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;\n\t\tsamplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]);\n\t\tsamplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);\n\t\tsamplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module);\n\t\tsamplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module));\n\t\treturn(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module));\n\t}\n\telse\n\t\treturn(_TIFFMultiply64(tif,nrows,TIFFTileRowSize64(tif),module));\n}', 'tmsize_t\nTIFFTileRowSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileRowSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileRowSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileRowSize64(TIFF* tif)\n{\n        static const char module[] = "TIFFTileRowSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint64 rowsize;\n\tuint64 tilerowsize;\n\tif (td->td_tilelength == 0)\n        {\n                TIFFErrorExt(tif->tif_clientdata,module,"Tile length is zero");\n                return 0;\n        }\n        if (td->td_tilewidth == 0)\n        {\n                TIFFErrorExt(tif->tif_clientdata,module,"Tile width is zero");\n\t\treturn (0);\n        }\n\trowsize = _TIFFMultiply64(tif, td->td_bitspersample, td->td_tilewidth,\n\t    "TIFFTileRowSize");\n\tif (td->td_planarconfig == PLANARCONFIG_CONTIG)\n        {\n                if (td->td_samplesperpixel == 0)\n                {\n                        TIFFErrorExt(tif->tif_clientdata,module,"Samples per pixel is zero");\n                        return 0;\n                }\n\t\trowsize = _TIFFMultiply64(tif, rowsize, td->td_samplesperpixel,\n\t\t    "TIFFTileRowSize");\n        }\n        tilerowsize=TIFFhowmany8_64(rowsize);\n        if (tilerowsize == 0)\n        {\n                TIFFErrorExt(tif->tif_clientdata,module,"Computed tile row size is zero");\n                return 0;\n        }\n\treturn (tilerowsize);\n}', 'tmsize_t\nTIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFReadEncodedTile(tif,\n\t    TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t    "%lu: Tile out of range, max %lu",\n\t\t    (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n    if( td->td_compression == COMPRESSION_NONE &&\n        size!=(tmsize_t)(-1) && size >= tilesize &&\n        !isMapped(tif) &&\n        ((tif->tif_flags&TIFF_NOREADRAW)==0) )\n    {\n        if (TIFFReadRawTile1(tif, tile, buf, tilesize, module) != tilesize)\n            return ((tmsize_t)(-1));\n        if (!isFillOrder(tif, td->td_fillorder) &&\n            (tif->tif_flags & TIFF_NOBITREV) == 0)\n            TIFFReverseBits(buf,tilesize);\n        (*tif->tif_postdecode)(tif,buf,tilesize);\n        return (tilesize);\n    }\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t    (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n        if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)\n            return 0;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif ((int64)bytecount <= 0) {\n#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t     (unsigned __int64) bytecount,\n\t\t\t\t     (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t     (unsigned long long) bytecount,\n\t\t\t\t     (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t    (isFillOrder(tif, td->td_fillorder)\n\t\t     || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\t\ttif->tif_rawdata = NULL;\n\t\t\t\ttif->tif_rawdatasize = 0;\n\t\t\t}\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t    td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n                        tif->tif_rawdataoff = 0;\n                        tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t\ttif->tif_flags |= TIFF_BUFFERMMAP;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t    "Data buffer too small to hold tile %lu",\n\t\t\t\t\t    (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (tif->tif_flags&TIFF_BUFFERMMAP) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t    bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n                        tif->tif_rawdataoff = 0;\n                        tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t    (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n                                                tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n        static const char module[] = "TIFFStartTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n        uint32 howmany32;\n        if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)\n                return 0;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n        howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);\n        if (howmany32 == 0) {\n                 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");\n                return 0;\n        }\n\ttif->tif_row = (tile % howmany32) * td->td_tilelength;\n        howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);\n        if (howmany32 == 0) {\n                TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");\n                return 0;\n        }\n\ttif->tif_col = (tile % howmany32) * td->td_tilewidth;\n        tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']