From 5ad5e64f8530a827482645986f5bb4e4613d0aa7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 3 Dec 2016 14:42:40 +0000 Subject: [PATCH] * tools/tiffcp.c: avoid potential division by zero is BitsPerSamples tag is missing. Reported by Agostino sarubbo. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2597 --- ChangeLog | 7 +++++++ tools/tiffcp.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/tiffcp.c b/tools/tiffcp.c index 6dfb9a91bfa9..c8e48c3c2bb3 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1378,7 +1378,7 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) uint8* bufp = (uint8*) buf; uint32 tw, tl; uint32 row; - uint16 bps, bytes_per_sample; + uint16 bps = 0, bytes_per_sample; tilebuf = _TIFFmalloc(tilesize); if (tilebuf == 0) @@ -1387,6 +1387,12 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) (void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw); (void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl); (void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps); + if( bps == 0 ) + { + TIFFError(TIFFFileName(in), "Error, cannot read BitsPerSample"); + status = 0; + goto done; + } assert( bps % 8 == 0 ); bytes_per_sample = bps/8; -- 2.12.0