Skip to content

Commit

Permalink
Merge pull request #3998 from chadawagner/master
Browse files Browse the repository at this point in the history
Fix bug in TIFF loading of BufferedReader
  • Loading branch information
radarhere committed Aug 22, 2019
2 parents a44e918 + 34330a7 commit d96f657
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/test_file_libtiff.py
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -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.")
Expand All @@ -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())

Expand Down

0 comments on commit d96f657

Please sign in to comment.