From 0a757b7085b399e71a22c4deb46332c9a1c9d0e2 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 1 Apr 2020 22:17:39 +0300 Subject: [PATCH 1/3] Initialise __frame = 0 --- src/PIL/PngImagePlugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 81a9e36af..2c51caf47 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -630,6 +630,7 @@ class PngImageFile(ImageFile.ImageFile): format = "PNG" format_description = "Portable network graphics" + __frame = 0 def _open(self): From 1c2b2b085a7bb50564e5d7ae64939bffe781574f Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 1 Apr 2020 22:32:14 +0300 Subject: [PATCH 2/3] Add test case --- Tests/test_file_png.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index b6da36530..d095c26a1 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -629,6 +629,10 @@ class TestFilePng: with Image.open(test_file) as reloaded: assert reloaded.info["exif"] == b"Exif\x00\x00exifstring" + def test_seek(self, tmp_path): + with Image.open(TEST_PNG_FILE) as im: + im.seek(0) + @pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS") @skip_unless_feature("zlib") From 2e9030ddca4a0c7f7cc7078f2a81c51a578bd1ae Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 2 Apr 2020 08:49:26 +0300 Subject: [PATCH 3/3] Initialise __frame = 0 in open, and test tell --- Tests/test_file_png.py | 4 ++++ src/PIL/PngImagePlugin.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index d095c26a1..f4b0de81b 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -629,6 +629,10 @@ class TestFilePng: with Image.open(test_file) as reloaded: assert reloaded.info["exif"] == b"Exif\x00\x00exifstring" + def test_tell(self, tmp_path): + with Image.open(TEST_PNG_FILE) as im: + assert im.tell() == 0 + def test_seek(self, tmp_path): with Image.open(TEST_PNG_FILE) as im: im.seek(0) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 2c51caf47..0291df4b0 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -630,13 +630,13 @@ class PngImageFile(ImageFile.ImageFile): format = "PNG" format_description = "Portable network graphics" - __frame = 0 def _open(self): if self.fp.read(8) != _MAGIC: raise SyntaxError("not a PNG file") self.__fp = self.fp + self.__frame = 0 # # Parse headers up to the first IDAT or fDAT chunk