From 45530d5ce1bcc9357907b7e5eeb6e54c6198358e 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 | 28 ++++++++++-------- 3 files changed, 18 insertions(+), 12 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; @@ -559,6 +548,7 @@ ImagingLibTiffDecode( uint16 planarconfig = 0; int planes = 1; ImagingShuffler unpackers[4]; + UINT32 img_width, img_height; memset(unpackers, 0, sizeof(ImagingShuffler) * 4); @@ -655,6 +645,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);