From c414810d12a7204eeaee764520f645e559be94a4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 5 Apr 2020 15:23:18 +1000 Subject: [PATCH 1/3] Replaced property methods for n_frames and is_animated with normal properties --- src/PIL/PngImagePlugin.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 0291df4b0..ee9d52b4c 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -673,7 +673,7 @@ class PngImageFile(ImageFile.ImageFile): self._text = None self.tile = self.png.im_tile self.custom_mimetype = self.png.im_custom_mimetype - self._n_frames = self.png.im_n_frames + self.n_frames = self.png.im_n_frames or 1 self.default_image = self.info.get("default_image", False) if self.png.im_palette: @@ -685,15 +685,16 @@ class PngImageFile(ImageFile.ImageFile): else: self.__prepare_idat = length # used by load_prepare() - if self._n_frames is not None: + if self.png.im_n_frames is not None: self._close_exclusive_fp_after_loading = False self.png.save_rewind() self.__rewind_idat = self.__prepare_idat self.__rewind = self.__fp.tell() if self.default_image: # IDAT chunk contains default image and not first animation frame - self._n_frames += 1 + self.n_frames += 1 self._seek(0) + self.is_animated = self.n_frames > 1 @property def text(self): @@ -710,16 +711,6 @@ class PngImageFile(ImageFile.ImageFile): self.seek(frame) return self._text - @property - def n_frames(self): - if self._n_frames is None: - return 1 - return self._n_frames - - @property - def is_animated(self): - return self._n_frames is not None and self._n_frames > 1 - def verify(self): """Verify PNG file""" From 7475c06b1c1b5145eff202d9bd3e05668825a9cd Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 5 Apr 2020 15:29:13 +1000 Subject: [PATCH 2/3] Assert that seeking too far raises an EOFError --- Tests/test_file_png.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 469d186e8..476995dd7 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -637,6 +637,9 @@ class TestFilePng: with Image.open(TEST_PNG_FILE) as im: im.seek(0) + with pytest.raises(EOFError): + im.seek(1) + @pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS") @skip_unless_feature("zlib") From f1f177ce800c5be7d06b0119b979c661c1bfbbb9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 6 Apr 2020 19:41:38 +1000 Subject: [PATCH 3/3] Fixed error making HTML from docs --- docs/reference/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/plugins.rst b/docs/reference/plugins.rst index 46f657fce..cc0742fde 100644 --- a/docs/reference/plugins.rst +++ b/docs/reference/plugins.rst @@ -229,7 +229,7 @@ Plugin reference ---------------------------- .. automodule:: PIL.PngImagePlugin - :members: ChunkStream, PngImageFile, PngStream, getchunks, is_cid, putchunk + :members: ChunkStream, PngStream, getchunks, is_cid, putchunk :show-inheritance: .. autoclass:: PIL.PngImagePlugin.ChunkStream :members: