From c290c1f228f88a84f15861a40ca03b82ad859165 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 31 Mar 2021 21:04:59 +0200 Subject: [PATCH] fixes crash-74d2 --- ...d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif | Bin 0 -> 1026 bytes Tests/test_tiff_crashes.py | 2 ++ src/libImaging/TiffDecode.c | 30 ++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 Tests/images/crash-74d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif diff --git a/Tests/images/crash-74d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif b/Tests/images/crash-74d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif new file mode 100644 index 0000000000000000000000000000000000000000..053e4e4e952ca9a0139f6d7a2b726c64b305fdc1 GIT binary patch literal 1026 zcmebD)M8L#W?-26NO_Ufk^28Y@PtFO{{OiTAm;z4e1ftr?jVtWr;6q**8~y^Pc%Fctuf9vD_|E>4lw{G>W*cD#KZ)Jz_a~+ZtcPSMFTBzV~tz!TG{~zT~ zY-iQb2xz?QzubGlL>U_`{-v*dU;p~I|NpOl(`#eHOLhlL?cZ{3m7HjcK`I}Y^8f#z zGzuI}UbV0)_%^qu?{ysize; } @@ -281,17 +281,6 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) { img.req_orientation = ORIENTATION_TOPLEFT; img.col_offset = 0; - if (state->xsize != img.width || state->ysize != img.height) { - TRACE( - ("Inconsistent Image Error: %d =? %d, %d =? %d", - state->xsize, - img.width, - state->ysize, - img.height)); - state->errcode = IMAGING_CODEC_BROKEN; - goto decodergba_err; - } - /* overflow check for row byte size */ if (INT_MAX / 4 < img.width) { state->errcode = IMAGING_CODEC_MEMORY; @@ -429,7 +418,7 @@ _decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imaging for (x = state->xoff; x < state->xsize; x += tile_width) { /* Sanity Check. Apparently in some cases, the TiffReadRGBA* functions have a different view of the size of the tiff than we're getting from - other functions. So, we need to check here. + other functions. So, we need to check here. */ if (!TIFFCheckTile(tiff, x, y, 0, plane)) { TRACE(("Check Tile Error, Tile at %dx%d\n", x, y)); @@ -568,6 +557,7 @@ ImagingLibTiffDecode( uint16 planarconfig = 0; int planes = 1; ImagingShuffler unpackers[4]; + UINT32 img_width, img_height; memset(unpackers, 0, sizeof(ImagingShuffler) * 4); @@ -664,6 +654,20 @@ ImagingLibTiffDecode( } } + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width); + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height); + + if (state->xsize != img_width || state->ysize != img_height) { + TRACE( + ("Inconsistent Image Error: %d =? %d, %d =? %d", + state->xsize, + img_width, + state->ysize, + img_height)); + state->errcode = IMAGING_CODEC_BROKEN; + goto decode_err; + } + TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric); TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);