From ab85290911f0d99e2abe407d6f84b0c2045feb80 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 13 Mar 2019 18:54:09 +1100 Subject: [PATCH] Fixed bug when seeking backwards and then forwards --- Tests/test_file_tiff.py | 5 +++++ src/PIL/TiffImagePlugin.py | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 9a4104b78..34911ed50 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -263,6 +263,11 @@ class TestFileTiff(PillowTestCase): self.assertEqual(im.size, (10, 10)) self.assertEqual(im.convert('RGB').getpixel((0, 0)), (255, 0, 0)) + im.seek(0) + im.load() + self.assertEqual(im.size, (10, 10)) + self.assertEqual(im.convert('RGB').getpixel((0, 0)), (0, 128, 0)) + im.seek(2) im.load() self.assertEqual(im.size, (20, 20)) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 2ea0f106e..34c6f39de 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1056,7 +1056,6 @@ class TiffImageFile(ImageFile.ImageFile): self.__frame += 1 self.fp.seek(self._frame_pos[frame]) self.tag_v2.load(self.fp) - self.__next = self.tag_v2.next # fill the legacy tag/ifd entries self.tag = self.ifd = ImageFileDirectory_v1.from_v2(self.tag_v2) self.__frame = frame @@ -1087,7 +1086,7 @@ class TiffImageFile(ImageFile.ImageFile): def load_end(self): # allow closing if we're on the first frame, there's no next # This is the ImageFile.load path only, libtiff specific below. - if self.__frame == 0 and not self.__next: + if len(self._frame_pos) == 1 and not self.__next: self._close_exclusive_fp_after_loading = True def _load_libtiff(self): @@ -1168,7 +1167,7 @@ class TiffImageFile(ImageFile.ImageFile): self.readonly = 0 # libtiff closed the fp in a, we need to close self.fp, if possible if self._exclusive_fp: - if self.__frame == 0 and not self.__next: + if len(self._frame_pos) == 1 and not self.__next: self.fp.close() self.fp = None # might be shared