Skip to content

Commit

Permalink
8559 suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 19, 2024
1 parent 0995305 commit e0f8056
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,10 +1216,6 @@ def seek(self, frame: int) -> None:
def _seek(self, frame: int) -> None:
self.fp = self._fp

# reset buffered io handle in case fp
# was passed to libtiff, invalidating the buffer
self.fp.tell()

while len(self._frame_pos) <= frame:
if not self.__next:
msg = "no more images in TIFF file"
Expand Down Expand Up @@ -1303,10 +1299,6 @@ def load_end(self) -> None:
if not self.is_animated:
self._close_exclusive_fp_after_loading = True

# reset buffered io handle in case fp
# was passed to libtiff, invalidating the buffer
self.fp.tell()

# load IFD data from fp before it is closed
exif = self.getexif()
for key in TiffTags.TAGS_V2_GROUPS:
Expand Down Expand Up @@ -1381,8 +1373,16 @@ def _load_libtiff(self) -> Image.core.PixelAccess | None:
logger.debug("have fileno, calling fileno version of the decoder.")
if not close_self_fp:
self.fp.seek(0)
# Save and restore the file position, because libtiff will move it
# outside of the Python runtime, and that will confuse
# io.BufferedReader and possibly others.
# This must use os.lseek, and not fp.seek(),
# because fp.seek() may just adjust it's internal buffer pointer
# and not actually move the OS file handle.
pos = os.lseek(fp, 0, os.SEEK_CUR)
# 4 bytes, otherwise the trace might error out
n, err = decoder.decode(b"fpfp")
os.lseek(fp, pos, os.SEEK_SET)
else:
# we have something else.
logger.debug("don't have fileno or getvalue. just reading")
Expand Down

0 comments on commit e0f8056

Please sign in to comment.