From 41f07a0cec9962be454c5f5708ab3fc75eecf4ad Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Sat, 29 Jun 2019 16:09:53 -0700 Subject: [PATCH] Add test for sampleformat corruption --- Tests/test_file_tiff.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 945372f86..fa1aa49fa 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -587,6 +587,28 @@ class TestFileTiff(PillowTestCase): im.load() self.assertFalse(fp.closed) + def test_sampleformat_not_corrupted(self): + # Assert that a TIFF image with SampleFormat=UINT tag is not corrupted + # when saving to a new file. + # Pillow 6.0 fails with "OSError: cannot identify image file". + import base64 + tiff = BytesIO( + base64.b64decode( + b'SUkqAAgAAAAPAP4ABAABAAAAAAAAAAABBAABAAAAAQAAAAEBBAABAAAAAQAA' + b'AAIBAwADAAAAwgAAAAMBAwABAAAACAAAAAYBAwABAAAAAgAAABEBBAABAAAA' + b'4AAAABUBAwABAAAAAwAAABYBBAABAAAAAQAAABcBBAABAAAACwAAABoBBQAB' + b'AAAAyAAAABsBBQABAAAA0AAAABwBAwABAAAAAQAAACgBAwABAAAAAQAAAFMB' + b'AwADAAAA2AAAAAAAAAAIAAgACAABAAAAAQAAAAEAAAABAAAAAQABAAEAAAB4' + b'nGNgYAAAAAMAAQ==' + ) + ) + out = BytesIO() + with Image.open(tiff) as im: + im.save(out, format='tiff') + out.seek(0) + with Image.open(out) as im: + im.load() + @unittest.skipUnless(sys.platform.startswith("win32"), "Windows only") class TestFileTiffW32(PillowTestCase):