(TIFFWriteEncodedTile): Fix Coverity 715976 and 715977 "Division

or modulo by zero".
This commit is contained in:
Bob Friesenhahn 2015-06-07 22:47:29 +00:00
parent 30f96cda9a
commit d480e894ef
2 changed files with 16 additions and 5 deletions

View File

@ -2,6 +2,8 @@
* libtiff/tif_write.c (TIFFWriteEncodedStrip): Fix Coverity 715975 * libtiff/tif_write.c (TIFFWriteEncodedStrip): Fix Coverity 715975
"Division or modulo by zero". "Division or modulo by zero".
(TIFFWriteEncodedTile): Fix Coverity 715976 and 715977 "Division
or modulo by zero".
* libtiff/tif_read.c (TIFFStartTile): Fix Coverity 715973 and * libtiff/tif_read.c (TIFFStartTile): Fix Coverity 715973 and
715974 "Division or modulo by zero". 715974 "Division or modulo by zero".

View File

@ -1,4 +1,4 @@
/* $Id: tif_write.c,v 1.39 2015-06-07 22:41:07 bfriesen Exp $ */ /* $Id: tif_write.c,v 1.40 2015-06-07 22:47:29 bfriesen Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -358,6 +358,7 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
static const char module[] = "TIFFWriteEncodedTile"; static const char module[] = "TIFFWriteEncodedTile";
TIFFDirectory *td; TIFFDirectory *td;
uint16 sample; uint16 sample;
uint32 howmany32;
if (!WRITECHECKTILES(tif, module)) if (!WRITECHECKTILES(tif, module))
return ((tmsize_t)(-1)); return ((tmsize_t)(-1));
@ -403,10 +404,18 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
* Compute tiles per row & per column to compute * Compute tiles per row & per column to compute
* current row and column * current row and column
*/ */
tif->tif_row = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
* td->td_tilelength; if (howmany32 == 0) {
tif->tif_col = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
* td->td_tilewidth; return ((tmsize_t)(-1));
}
tif->tif_row = (tile % howmany32) * td->td_tilelength;
howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);
if (howmany32 == 0) {
TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
return ((tmsize_t)(-1));
}
tif->tif_col = (tile % howmany32) * td->td_tilewidth;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupencode)(tif)) if (!(*tif->tif_setupencode)(tif))