summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorbfriesen <bfriesen>2015-05-28 01:59:10 +0000
committerbfriesen <bfriesen>2015-05-28 01:59:10 +0000
commitb5c87c713cbfb22a65704d3095f113f7bbec4af1 (patch)
treebee81f66c2c98bae0e85191676af48dcf75fea1a /tools
parent836d3b836804d9a5c6a0e9c0e211a2e2cb65ebd3 (diff)
downloadlibtiff-b5c87c713cbfb22a65704d3095f113f7bbec4af1.tar.gz
(readContigStripsIntoBuffer): Fix Coverity 1024545 "Division or
modulo by zero".
Diffstat (limited to 'tools')
-rw-r--r--tools/tiffcrop.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index 17634af0..cb27e24f 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -1,4 +1,4 @@
-/* $Id: tiffcrop.c,v 1.26 2015-05-28 01:50:23 bfriesen Exp $ */
+/* $Id: tiffcrop.c,v 1.27 2015-05-28 01:59:10 bfriesen Exp $ */
/* tiffcrop.c -- a port of tiffcp.c extended to include manipulations of
* the image data through additional options listed below
@@ -3599,34 +3599,38 @@ extractContigSamplesToTileBuffer(uint8 *out, uint8 *in, uint32 rows, uint32 cols
} /* end extractContigSamplesToTileBuffer */
static int readContigStripsIntoBuffer (TIFF* in, uint8* buf)
- {
- uint8* bufp = buf;
- int32 bytes_read = 0;
- uint16 strip, nstrips = TIFFNumberOfStrips(in);
- uint32 stripsize = TIFFStripSize(in);
- uint32 rows = 0;
- uint32 rps = TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps);
- tsize_t scanline_size = TIFFScanlineSize(in);
-
- for (strip = 0; strip < nstrips; strip++)
- {
- bytes_read = TIFFReadEncodedStrip (in, strip, bufp, -1);
- rows = bytes_read / scanline_size;
- if ((strip < (nstrips - 1)) && (bytes_read != (int32)stripsize))
- TIFFError("", "Strip %d: read %lu bytes, strip size %lu",
- (int)strip + 1, (unsigned long) bytes_read, (unsigned long)stripsize);
+{
+ uint8* bufp = buf;
+ int32 bytes_read = 0;
+ uint16 strip, nstrips = TIFFNumberOfStrips(in);
+ uint32 stripsize = TIFFStripSize(in);
+ uint32 rows = 0;
+ uint32 rps = TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps);
+ tsize_t scanline_size = TIFFScanlineSize(in);
+
+ if (scanline_size == 0) {
+ TIFFError("", "TIFF scanline size is zero!");
+ return 0;
+ }
- if (bytes_read < 0 && !ignore)
- {
- TIFFError("", "Error reading strip %lu after %lu rows",
- (unsigned long) strip, (unsigned long)rows);
- return 0;
- }
- bufp += bytes_read;
- }
+ for (strip = 0; strip < nstrips; strip++) {
+ bytes_read = TIFFReadEncodedStrip (in, strip, bufp, -1);
+ rows = bytes_read / scanline_size;
+ if ((strip < (nstrips - 1)) && (bytes_read != (int32)stripsize))
+ TIFFError("", "Strip %d: read %lu bytes, strip size %lu",
+ (int)strip + 1, (unsigned long) bytes_read,
+ (unsigned long)stripsize);
+
+ if (bytes_read < 0 && !ignore) {
+ TIFFError("", "Error reading strip %lu after %lu rows",
+ (unsigned long) strip, (unsigned long)rows);
+ return 0;
+ }
+ bufp += bytes_read;
+ }
- return 1;
- } /* end readContigStripsIntoBuffer */
+ return 1;
+} /* end readContigStripsIntoBuffer */
static int
combineSeparateSamplesBytes (unsigned char *srcbuffs[], unsigned char *out,