Merge pull request #3998 from chadawagner/master

Fix bug in TIFF loading of BufferedReader
This commit is contained in:
Andrew Murray 2019-08-23 06:25:30 +10:00 committed by GitHub
commit d96f657328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -81,6 +81,19 @@ class TestFileLibTiff(LibTiffTestCase):
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")

View File

@ -1164,7 +1164,7 @@ class TiffImageFile(ImageFile.ImageFile):
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.")
@ -1175,6 +1175,7 @@ class TiffImageFile(ImageFile.ImageFile):
# 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())