From 88be36c27aade7af422d5bf934d05a8a4b51d7d3 Mon Sep 17 00:00:00 2001 From: chadawagner Date: Tue, 30 Jul 2019 11:26:04 -0700 Subject: [PATCH 1/4] check prior fp result, do not use if False --- src/PIL/TiffImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index dabcf8eb4a8..fb394af1649 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1164,7 +1164,7 @@ def _load_libtiff(self): if DEBUG: print("have getvalue. just sending in a string from getvalue") n, err = decoder.decode(self.fp.getvalue()) - elif hasattr(self.fp, "fileno"): + elif fp: # we've got a actual file on disk, pass in the fp. if DEBUG: print("have fileno, calling fileno version of the decoder.") From 597ca79b1b01f446615323c67686dd205523ba96 Mon Sep 17 00:00:00 2001 From: chadawagner Date: Tue, 30 Jul 2019 11:28:44 -0700 Subject: [PATCH 2/4] rewind before decode, consistent with other cases --- src/PIL/TiffImagePlugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index fb394af1649..bb86c53aa09 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1175,6 +1175,7 @@ def _load_libtiff(self): # we have something else. if DEBUG: print("don't have fileno or getvalue. just reading") + self.fp.seek(0) # UNDONE -- so much for that buffer size thing. n, err = decoder.decode(self.fp.read()) From 457a97dde8232eb4b70e8704749ddd4094a4d257 Mon Sep 17 00:00:00 2001 From: chadawagner Date: Fri, 2 Aug 2019 17:26:10 -0700 Subject: [PATCH 3/4] added test for reading TIFF from non-disk file obj --- Tests/test_file_libtiff.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index bc5003f5fc2..4ddde047a9e 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -81,6 +81,19 @@ def test_g4_tiff_bytesio(self): self.assertEqual(im.size, (500, 500)) self._assert_noerr(im) + def test_g4_non_disk_file_object(self): + """Testing loading from non-disk non-bytesio file object""" + test_file = "Tests/images/hopper_g4_500.tif" + s = io.BytesIO() + with open(test_file, "rb") as f: + s.write(f.read()) + s.seek(0) + r = io.BufferedReader(s) + im = Image.open(r) + + self.assertEqual(im.size, (500, 500)) + self._assert_noerr(im) + def test_g4_eq_png(self): """ Checking that we're actually getting the data that we expect""" png = Image.open("Tests/images/hopper_bw_500.png") From 34330a7aa0b3f0585f5540c59f40690769cb22e5 Mon Sep 17 00:00:00 2001 From: chadawagner Date: Mon, 19 Aug 2019 09:46:07 -0700 Subject: [PATCH 4/4] Update Tests/test_file_libtiff.py Co-Authored-By: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_file_libtiff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 4ddde047a9e..6339d878acd 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -82,7 +82,7 @@ def test_g4_tiff_bytesio(self): self._assert_noerr(im) def test_g4_non_disk_file_object(self): - """Testing loading from non-disk non-bytesio file object""" + """Testing loading from non-disk non-BytesIO file object""" test_file = "Tests/images/hopper_g4_500.tif" s = io.BytesIO() with open(test_file, "rb") as f: