From 5b52559d3944a55de02ab210e2ae05f636c3dbd8 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/ChangeLog b/ChangeLog index e41d00c4..0d7b12d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-12-03 Even Rouault + + * 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 + 2016-12-03 Even Rouault * tools/tiffinfo.c: fix null pointer dereference in -r mode when the image has diff --git a/tools/tiffcp.c b/tools/tiffcp.c index 6dfb9a91..c8e48c3c 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1,4 +1,4 @@ -/* $Id: tiffcp.c,v 1.56 2016-12-02 22:13:32 erouault Exp $ */ +/* $Id: tiffcp.c,v 1.57 2016-12-03 14:42:40 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -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;