Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in TIFF loading of BufferedReader #3998

Merged
merged 4 commits into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"""
chadawagner marked this conversation as resolved.
Show resolved Hide resolved
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