From 92adfaad2bbe86376cb20a7618d374ea961883ae Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 5 Apr 2020 15:23:18 +1000 Subject: [PATCH 1/6] 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 0291df4b097..ee9d52b4cc6 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -673,7 +673,7 @@ def _open(self): 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 @@ def _open(self): 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 @@ def text(self): 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 ab1835df5ca784e23b99703140967985af4267ba Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 5 Apr 2020 15:29:13 +1000 Subject: [PATCH 2/6] 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 469d186e816..476995dd7a6 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -637,6 +637,9 @@ def test_seek(self): 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 1f3ccd12985bc6ff605496145ae350c0264faebd Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 6 Apr 2020 19:41:38 +1000 Subject: [PATCH 3/6] 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 46f657fce57..cc0742fde44 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: From e038c84ca9de033c9a035ad7ffe9cf3a9d99c58a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 5 Apr 2020 13:14:08 +1000 Subject: [PATCH 4/6] Update pip to fix pyqt5 install --- .ci/install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/install.sh b/.ci/install.sh index 8e819631aa5..180fa6582ce 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -7,6 +7,7 @@ sudo apt-get -qq install libfreetype6-dev liblcms2-dev python3-tk\ ghostscript libffi-dev libjpeg-turbo-progs libopenjp2-7-dev\ cmake imagemagick libharfbuzz-dev libfribidi-dev +pip install --upgrade pip PYTHONOPTIMIZE=0 pip install cffi pip install coverage pip install olefile @@ -20,7 +21,7 @@ if [[ $TRAVIS_PYTHON_VERSION == 3.* ]]; then # "ERROR: Could not find a version that satisfies the requirement pyqt5" if [[ $TRAVIS_CPU_ARCH == "amd64" ]]; then sudo apt-get -qq install pyqt5-dev-tools - pip install pyqt5!=5.14.1 + pip install pyqt5 fi fi From f6358a68f0e6fbaf7e964fe30db7b7704fbc44c7 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 25 Apr 2020 08:46:40 +0300 Subject: [PATCH 5/6] Release notes for 7.1.2 --- CHANGES.rst | 6 ++++++ docs/releasenotes/7.1.2.rst | 16 ++++++++++++++++ docs/releasenotes/index.rst | 1 + 3 files changed, 23 insertions(+) create mode 100644 docs/releasenotes/7.1.2.rst diff --git a/CHANGES.rst b/CHANGES.rst index 4ece866f2d4..6474d006988 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ Changelog (Pillow) ================== +7.1.2 (2020-04-25) +------------------ + +- Raise an EOFError when seeking too far in PNG #4528 + [radarhere] + 7.1.1 (2020-04-02) ------------------ diff --git a/docs/releasenotes/7.1.2.rst b/docs/releasenotes/7.1.2.rst new file mode 100644 index 00000000000..c9d0d54eb06 --- /dev/null +++ b/docs/releasenotes/7.1.2.rst @@ -0,0 +1,16 @@ +7.1.2 +----- + +Fix another regression seeking PNG files +======================================== + +This fixes a regression introduced in 7.1.0 when adding support for APNG files. + +When calling ``seek(n)`` on a regular PNG where ``n > 0``, it failed to raise an +``EOFError`` as it should have done, resulting in: + +.. code-block:: python + + AttributeError: 'NoneType' object has no attribute 'read' + +Pillow 7.1.2 now raises the correct exception. diff --git a/docs/releasenotes/index.rst b/docs/releasenotes/index.rst index 7cdb5849448..575931c4d93 100644 --- a/docs/releasenotes/index.rst +++ b/docs/releasenotes/index.rst @@ -6,6 +6,7 @@ Release Notes .. toctree:: :maxdepth: 2 + 7.1.2 7.1.1 7.1.0 7.0.0 From 4f6145655b6fa35ec8dd3600041418087e399758 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 25 Apr 2020 08:47:14 +0300 Subject: [PATCH 6/6] 7.1.2 version bump --- src/PIL/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/_version.py b/src/PIL/_version.py index 857b2726e56..1af2909f019 100644 --- a/src/PIL/_version.py +++ b/src/PIL/_version.py @@ -1,2 +1,2 @@ # Master version for Pillow -__version__ = "7.1.1" +__version__ = "7.1.2"