From bb5a090f60ed08941e5bdd7077f9a53caec99b57 Mon Sep 17 00:00:00 2001 From: Mikhail Iurkov Date: Wed, 9 Feb 2022 16:16:33 +0300 Subject: [PATCH 1/2] Drop excess values in BITSPERSAMPLE --- Tests/images/tiff_wrong_bits_per_sample_2.tiff | Bin 0 -> 1041 bytes Tests/test_file_tiff.py | 14 +++++++++----- src/PIL/TiffImagePlugin.py | 8 ++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 Tests/images/tiff_wrong_bits_per_sample_2.tiff diff --git a/Tests/images/tiff_wrong_bits_per_sample_2.tiff b/Tests/images/tiff_wrong_bits_per_sample_2.tiff new file mode 100644 index 0000000000000000000000000000000000000000..d44176ce76ce43f738cf215db0b7974fe3e3ff2a GIT binary patch literal 1041 zcmebD)MDUZW*BkcKPmwFA1DAJAu^BopA1 len(bps_tuple) and len(bps_tuple) == 1: + # while should have more. Or have more values + # than expected. Fix it + bps_actual_count = len(bps_tuple) + if bps_count < bps_actual_count: + bps_tuple = bps_tuple[:bps_count] + elif bps_count > bps_actual_count and bps_actual_count == 1: bps_tuple = bps_tuple * bps_count samplesPerPixel = self.tag_v2.get( From 2bbf5f0981bbaa9a0ba8a5411b537389d3d6904f Mon Sep 17 00:00:00 2001 From: Mikhail Iurkov Date: Wed, 9 Feb 2022 16:53:27 +0300 Subject: [PATCH 2/2] Lint --- Tests/test_file_tiff.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index fd526089a..55e2c8be3 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -90,10 +90,13 @@ class TestFileTiff: assert_image_similar_tofile(im, "Tests/images/pil136.png", 1) - @pytest.mark.parametrize("file_name,mode,w,h,offset", [ - ("tiff_wrong_bits_per_sample.tiff","RGBA",52,53,160), - ("tiff_wrong_bits_per_sample_2.tiff","RGB",16,16,8), - ]) + @pytest.mark.parametrize( + "file_name,mode,w,h,offset", + [ + ("tiff_wrong_bits_per_sample.tiff", "RGBA", 52, 53, 160), + ("tiff_wrong_bits_per_sample_2.tiff", "RGB", 16, 16, 8), + ], + ) def test_wrong_bits_per_sample(self, file_name, mode, w, h, offset): with Image.open("Tests/images/" + file_name) as im: assert im.mode == mode