112 lines
3.3 KiB
Diff
112 lines
3.3 KiB
Diff
|
--- tiff-4.0.6/tools/tiffcrop.c 2015-08-29 00:17:08.312151629 +0200
|
||
|
+++ tiff-4.0.6/tools/tiffcrop.c 2016-09-01 16:21:40.874478425 +0200
|
||
|
@@ -798,6 +798,11 @@
|
||
|
}
|
||
|
|
||
|
tile_buffsize = tilesize;
|
||
|
+ if (tilesize == 0 || tile_rowsize == 0)
|
||
|
+ {
|
||
|
+ TIFFError("readContigTilesIntoBuffer", "Tile size or tile rowsize is zero");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
|
||
|
if (tilesize < (tsize_t)(tl * tile_rowsize))
|
||
|
{
|
||
|
@@ -807,6 +812,11 @@
|
||
|
tilesize, tl * tile_rowsize);
|
||
|
#endif
|
||
|
tile_buffsize = tl * tile_rowsize;
|
||
|
+ if (tl != (tile_buffsize / tile_rowsize))
|
||
|
+ {
|
||
|
+ TIFFError("readContigTilesIntoBuffer", "Integer overflow when calculating buffer size.");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
tilebuf = _TIFFmalloc(tile_buffsize);
|
||
|
@@ -1210,6 +1220,12 @@
|
||
|
!TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps) )
|
||
|
return 1;
|
||
|
|
||
|
+ if (tilesize == 0 || tile_rowsize == 0 || tl == 0 || tw == 0)
|
||
|
+ {
|
||
|
+ TIFFError("writeBufferToContigTiles", "Tile size, tile row size, tile width, or tile length is zero");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
+
|
||
|
tile_buffsize = tilesize;
|
||
|
if (tilesize < (tsize_t)(tl * tile_rowsize))
|
||
|
{
|
||
|
@@ -1219,6 +1235,11 @@
|
||
|
tilesize, tl * tile_rowsize);
|
||
|
#endif
|
||
|
tile_buffsize = tl * tile_rowsize;
|
||
|
+ if (tl != tile_buffsize / tile_rowsize)
|
||
|
+ {
|
||
|
+ TIFFError("writeBufferToContigTiles", "Integer overflow when calculating buffer size");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
tilebuf = _TIFFmalloc(tile_buffsize);
|
||
|
@@ -5945,12 +5966,27 @@
|
||
|
TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);
|
||
|
|
||
|
tile_rowsize = TIFFTileRowSize(in);
|
||
|
+ if (ntiles == 0 || tlsize == 0 || tile_rowsize == 0)
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "File appears to be tiled, but the number of tiles, tile size, or tile rowsize is zero.");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
buffsize = tlsize * ntiles;
|
||
|
-
|
||
|
+ if (tlsize != (buffsize / ntiles))
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "Integer overflow when calculating buffer size");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
|
||
|
if (buffsize < (uint32)(ntiles * tl * tile_rowsize))
|
||
|
{
|
||
|
buffsize = ntiles * tl * tile_rowsize;
|
||
|
+ if (ntiles != (buffsize / tl / tile_rowsize))
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "Integer overflow when calculating buffer size");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
+
|
||
|
#ifdef DEBUG2
|
||
|
TIFFError("loadImage",
|
||
|
"Tilesize %u is too small, using ntiles * tilelength * tilerowsize %lu",
|
||
|
@@ -5965,12 +6001,29 @@
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
+ uint32 buffsize_check;
|
||
|
readunit = STRIP;
|
||
|
TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
|
||
|
stsize = TIFFStripSize(in);
|
||
|
nstrips = TIFFNumberOfStrips(in);
|
||
|
- buffsize = stsize * nstrips;
|
||
|
+ if (nstrips == 0 || stsize == 0)
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "File appears to be striped, but the number of stipes or stripe size is zero.");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
|
||
|
+ buffsize = stsize * nstrips;
|
||
|
+ if (stsize != (buffsize / nstrips))
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "Integer overflow when calculating buffer size");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
+ buffsize_check = ((length * width * spp * bps) + 7);
|
||
|
+ if (length != ((buffsize_check - 7) / width / spp / bps))
|
||
|
+ {
|
||
|
+ TIFFError("loadImage", "Integer overflow detected.");
|
||
|
+ exit(-1);
|
||
|
+ }
|
||
|
if (buffsize < (uint32) (((length * width * spp * bps) + 7) / 8))
|
||
|
{
|
||
|
buffsize = ((length * width * spp * bps) + 7) / 8;
|