From 812b46901ef4abeea2523ccc1a667765465d55bb Mon Sep 17 00:00:00 2001 From: Frederick Price Date: Fri, 21 Apr 2023 23:47:55 -0400 Subject: [PATCH] Cherry picked 13f2c5ae14901c89c38f898496102afd9daeaf6d --- ...5817ca0f8c663be7ab4b9e717b02c661e66834.tif | Bin 0 -> 88 bytes Tests/test_file_tiff.py | 69 +++++++++--------- src/PIL/TiffImagePlugin.py | 25 ++++++- 3 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 Tests/images/oom-225817ca0f8c663be7ab4b9e717b02c661e66834.tif diff --git a/Tests/images/oom-225817ca0f8c663be7ab4b9e717b02c661e66834.tif b/Tests/images/oom-225817ca0f8c663be7ab4b9e717b02c661e66834.tif new file mode 100644 index 0000000000000000000000000000000000000000..01dca594f53e22fda9b11ed5b704326680af1b8c GIT binary patch literal 88 zcmebD)MDUZU|`^8U|?isU<9(bfS3`=2FWl%*#bZ|Gn5Td$A-ifWn=;Cox~s{WCDf& DV5 len(bps_tuple) and len(bps_tuple) == 1: - bps_tuple = bps_tuple * bps_count + bps_actual_count = len(bps_tuple) + samples_per_pixel = self.tag_v2.get( + SAMPLESPERPIXEL, + 3 if self._compression == "tiff_jpeg" and photo in (2, 6) else 1, + ) + + if samples_per_pixel > MAX_SAMPLESPERPIXEL: + # DOS check, samples_per_pixel can be a Long, and we extend the tuple below + logger.error("More samples per pixel than can be decoded: %s", samples_per_pixel) + raise SyntaxError("Invalid value for samples per pixel") + + if samples_per_pixel < bps_actual_count: + # If a file has more values in bps_tuple than expected, + # remove the excess. + bps_tuple = bps_tuple[:samples_per_pixel] + elif samples_per_pixel > bps_actual_count and bps_actual_count == 1: + # If a file has only one value in bps_tuple, when it should have more, + # presume it is the same number of bits for all of the samples. + bps_tuple = bps_tuple * samples_per_pixel # mode: check photometric interpretation and bits per pixel key = (