Skip to content

Commit

Permalink
Merge pull request #4076 from radarhere/loading
Browse files Browse the repository at this point in the history
Do not seek if the file pointer is about to be closed
  • Loading branch information
hugovk committed Sep 21, 2019
2 parents 0c07e99 + f9236a1 commit 89c901a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/PIL/TiffImagePlugin.py
Expand Up @@ -1165,6 +1165,7 @@ def _load_libtiff(self):
except ValueError:
raise IOError("Couldn't set the image")

close_self_fp = self._exclusive_fp and not self._is_animated
if hasattr(self.fp, "getvalue"):
# We've got a stringio like thing passed in. Yay for all in memory.
# The decoder needs the entire file in one shot, so there's not
Expand All @@ -1182,7 +1183,8 @@ def _load_libtiff(self):
# we've got a actual file on disk, pass in the fp.
if DEBUG:
print("have fileno, calling fileno version of the decoder.")
self.fp.seek(0)
if not close_self_fp:
self.fp.seek(0)
# 4 bytes, otherwise the trace might error out
n, err = decoder.decode(b"fpfp")
else:
Expand All @@ -1199,7 +1201,7 @@ def _load_libtiff(self):
self.load_end()

# libtiff closed the fp in a, we need to close self.fp, if possible
if self._exclusive_fp and not self._is_animated:
if close_self_fp:
self.fp.close()
self.fp = None # might be shared

Expand Down

0 comments on commit 89c901a

Please sign in to comment.