|
|
d77016 |
From 3d451e3f95cbb67dd771a986991b5b6107140c4e Mon Sep 17 00:00:00 2001
|
|
|
d77016 |
From: Even Rouault <even.rouault@spatialys.com>
|
|
|
d77016 |
Date: Thu, 15 Aug 2019 15:05:28 +0200
|
|
|
d77016 |
Subject: [PATCH] RGBA interface: fix integer overflow potentially causing
|
|
|
d77016 |
write heap buffer overflow, especially on 32 bit builds. Fixes
|
|
|
d77016 |
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16443. Credit to OSS
|
|
|
d77016 |
Fuzz
|
|
|
d77016 |
|
|
|
d77016 |
---
|
|
|
d77016 |
libtiff/tif_getimage.c | 26 ++++++++++++++++++++------
|
|
|
d77016 |
1 file changed, 20 insertions(+), 6 deletions(-)
|
|
|
d77016 |
|
|
|
d77016 |
diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c
|
|
|
d77016 |
index ec09fea..c6edd27 100644
|
|
|
d77016 |
--- a/libtiff/tif_getimage.c
|
|
|
d77016 |
+++ b/libtiff/tif_getimage.c
|
|
|
d77016 |
@@ -951,16 +951,23 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
|
|
d77016 |
for (row = 0; row < h; row += nrow)
|
|
|
d77016 |
{
|
|
|
d77016 |
+ uint32 temp;
|
|
|
d77016 |
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
|
|
d77016 |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
|
d77016 |
nrowsub = nrow;
|
|
|
d77016 |
if ((nrowsub%subsamplingver)!=0)
|
|
|
d77016 |
nrowsub+=subsamplingver-nrowsub%subsamplingver;
|
|
|
d77016 |
+ temp = (row + img->row_offset)%rowsperstrip + nrowsub;
|
|
|
d77016 |
+ if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
|
|
|
d77016 |
+ {
|
|
|
d77016 |
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripContig");
|
|
|
d77016 |
+ return 0;
|
|
|
d77016 |
+ }
|
|
|
d77016 |
if (_TIFFReadEncodedStripAndAllocBuffer(tif,
|
|
|
d77016 |
TIFFComputeStrip(tif,row+img->row_offset, 0),
|
|
|
d77016 |
(void**)(&buf),
|
|
|
d77016 |
maxstripsize,
|
|
|
d77016 |
- ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
+ temp * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
&& (buf == NULL || img->stoponerr))
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
@@ -1053,15 +1060,22 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
fromskew = (w < imagewidth ? imagewidth - w : 0);
|
|
|
d77016 |
for (row = 0; row < h; row += nrow)
|
|
|
d77016 |
{
|
|
|
d77016 |
+ uint32 temp;
|
|
|
d77016 |
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
|
|
|
d77016 |
nrow = (row + rowstoread > h ? h - row : rowstoread);
|
|
|
d77016 |
offset_row = row + img->row_offset;
|
|
|
d77016 |
+ temp = (row + img->row_offset)%rowsperstrip + nrow;
|
|
|
d77016 |
+ if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
|
|
|
d77016 |
+ {
|
|
|
d77016 |
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripSeparate");
|
|
|
d77016 |
+ return 0;
|
|
|
d77016 |
+ }
|
|
|
d77016 |
if( buf == NULL )
|
|
|
d77016 |
{
|
|
|
d77016 |
if (_TIFFReadEncodedStripAndAllocBuffer(
|
|
|
d77016 |
tif, TIFFComputeStrip(tif, offset_row, 0),
|
|
|
d77016 |
(void**) &buf, bufsize,
|
|
|
d77016 |
- ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
+ temp * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
&& (buf == NULL || img->stoponerr))
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
@@ -1081,7 +1095,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
}
|
|
|
d77016 |
}
|
|
|
d77016 |
else if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
|
|
|
d77016 |
- p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
+ p0, temp * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
&& img->stoponerr)
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
@@ -1089,7 +1103,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
}
|
|
|
d77016 |
if (colorchannels > 1
|
|
|
d77016 |
&& TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1),
|
|
|
d77016 |
- p1, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1)
|
|
|
d77016 |
+ p1, temp * scanline) == (tmsize_t)(-1)
|
|
|
d77016 |
&& img->stoponerr)
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
@@ -1097,7 +1111,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
}
|
|
|
d77016 |
if (colorchannels > 1
|
|
|
d77016 |
&& TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2),
|
|
|
d77016 |
- p2, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1)
|
|
|
d77016 |
+ p2, temp * scanline) == (tmsize_t)(-1)
|
|
|
d77016 |
&& img->stoponerr)
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
@@ -1106,7 +1120,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
|
|
|
d77016 |
if (alpha)
|
|
|
d77016 |
{
|
|
|
d77016 |
if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, colorchannels),
|
|
|
d77016 |
- pa, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
+ pa, temp * scanline)==(tmsize_t)(-1)
|
|
|
d77016 |
&& img->stoponerr)
|
|
|
d77016 |
{
|
|
|
d77016 |
ret = 0;
|
|
|
d77016 |
--
|
|
|
d77016 |
2.21.1
|
|
|
d77016 |
|