summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorerouault <erouault>2016-12-03 15:44:15 +0000
committererouault <erouault>2016-12-03 15:44:15 +0000
commit4dda6369039cdfcc07841a5a14b6f4e373ff001c (patch)
treeb1147186a8f6af4db06907f39951db2eb58531e7 /tools
parentb17885b7b736d60a62090fd31ec81ee65b5caf87 (diff)
downloadlibtiff-4dda6369039cdfcc07841a5a14b6f4e373ff001c.tar.gz
* 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=2607
Diffstat (limited to 'tools')
-rw-r--r--tools/tiffcp.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index c8e48c3c..142cbb0e 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -1,4 +1,4 @@
-/* $Id: tiffcp.c,v 1.57 2016-12-03 14:42:40 erouault Exp $ */
+/* $Id: tiffcp.c,v 1.58 2016-12-03 15:44:15 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -1569,7 +1569,7 @@ DECLAREwriteFunc(writeBufferToSeparateTiles)
uint8* bufp = (uint8*) buf;
uint32 tl, tw;
uint32 row;
- uint16 bps, bytes_per_sample;
+ uint16 bps = 0, bytes_per_sample;
obuf = _TIFFmalloc(TIFFTileSize(out));
if (obuf == NULL)
@@ -1578,6 +1578,12 @@ DECLAREwriteFunc(writeBufferToSeparateTiles)
(void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);
(void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);
(void) TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);
+ if( bps == 0 )
+ {
+ TIFFError(TIFFFileName(out), "Error, cannot read BitsPerSample");
+ _TIFFfree(obuf);
+ return 0;
+ }
assert( bps % 8 == 0 );
bytes_per_sample = bps/8;