From 9a977b975cd871ef9a9128b72414c0de3a292591 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 29 Sep 2019 14:15:48 +1000 Subject: [PATCH] Raise error if dimension is a string --- Tests/images/string_dimension.tiff | Bin 0 -> 483 bytes Tests/test_file_tiff.py | 5 +++++ src/PIL/TiffImagePlugin.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Tests/images/string_dimension.tiff diff --git a/Tests/images/string_dimension.tiff b/Tests/images/string_dimension.tiff new file mode 100644 index 0000000000000000000000000000000000000000..d0b55830128495194a82252d3cf7c4d4cae0931c GIT binary patch literal 483 zcmebD)M8k`z`)R8{~*9Zg|kh8VgI4#AJPZd7_|03?EgOd?~ecmmq+Ulb-K)F>OG$P z(L>+^vvSvg84E5@4K%E0*&6*!HDCo3r@s7ty^k6vW!LF2P2FPl+D_}z`*(wr2g%Hka!nV9LVHlWMpFS05a-;h6ysVfX(Cp z@`a#kKz4{CvBf~_|2P0pEdvXKI0Mw2H8U9GKtc>sjI3aT+kmD?L)m>mwhYYRgVX^a hyBvUK@&M^+K=TEFbeb%qUP)#eNQwdEY%l}J0staUza0Po literal 0 HcmV?d00001 diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 2baeb6ae054..2d15de2bd56 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -587,6 +587,11 @@ def test_close_on_load_nonexclusive(self): im.load() self.assertFalse(fp.closed) + def test_string_dimension(self): + # Assert that an error is raised if one of the dimensions is a string + with self.assertRaises(ValueError): + Image.open("Tests/images/string_dimension.tiff") + @unittest.skipUnless(sys.platform.startswith("win32"), "Windows only") class TestFileTiffW32(PillowTestCase): diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 9fcffb74273..a927cd3ed90 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1239,8 +1239,8 @@ def _setup(self): print("- YCbCr subsampling:", self.tag.get(530)) # size - xsize = self.tag_v2.get(IMAGEWIDTH) - ysize = self.tag_v2.get(IMAGELENGTH) + xsize = int(self.tag_v2.get(IMAGEWIDTH)) + ysize = int(self.tag_v2.get(IMAGELENGTH)) self._size = xsize, ysize if DEBUG: