Skip to content

Commit 8b8076b

Browse files
wiredfoolradarhere
authored andcommitted
* Invalid tile boundaries lead to OOB Read in TiffDecode.c, in TiffReadRGBATile * Check the tile validity before attempting to read.
1 parent e25be1e commit 8b8076b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
Binary file not shown.

Tests/test_tiff_crashes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Tests/images/crash-4f085cc12ece8cde18758d42608bed6a2a2cfb1c.tif",
3333
"Tests/images/crash-86214e58da443d2b80820cff9677a38a33dcbbca.tif",
3434
"Tests/images/crash-f46f5b2f43c370fe65706c11449f567ecc345e74.tif",
35+
"Tests/images/crash-63b1dffefc8c075ddc606c0a2f5fdc15ece78863.tif",
3536
],
3637
)
3738
@pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data")

src/libImaging/TiffDecode.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,15 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_
479479

480480
for (y = state->yoff; y < state->ysize; y += tile_length) {
481481
for (x = state->xoff; x < state->xsize; x += tile_width) {
482+
/* Sanity Check. Apparently in some cases, the TiffReadRGBA* functions
483+
have a different view of the size of the tiff than we're getting from
484+
other functions. So, we need to check here.
485+
*/
486+
if (!TIFFCheckTile(tiff, x, y, 0, 0)) {
487+
TRACE(("Check Tile Error, Tile at %dx%d\n", x, y));
488+
state->errcode = IMAGING_CODEC_BROKEN;
489+
goto decode_err;
490+
}
482491
if (isYCbCr) {
483492
/* To avoid dealing with YCbCr subsampling, let libtiff handle it */
484493
if (!TIFFReadRGBATile(tiff, x, y, (UINT32 *)state->buffer)) {

0 commit comments

Comments
 (0)