From 6d99f9193f0abe211e611f2d9909a4eb5881d270 Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Sun, 7 Jan 2024 16:00:58 -0500 Subject: [PATCH 1/6] Fix info for first frame of apng images getting clobbered when seeking to the first frame multiple times. --- src/PIL/PngImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index e4ed9388011..823f1249285 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -378,7 +378,7 @@ def save_rewind(self): } def rewind(self): - self.im_info = self.rewind_state["info"] + self.im_info = self.rewind_state["info"].copy() self.im_tile = self.rewind_state["tile"] self._seq_num = self.rewind_state["seq_num"] From 3515f997ce06664d8ec42cc21e39eef9897dbaeb Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Sun, 7 Jan 2024 20:42:52 -0500 Subject: [PATCH 2/6] Add test against info of apng images getting clobbered when seeking to the first frame multiple times. --- Tests/images/apng/issue_7700.png | Bin 0 -> 233 bytes Tests/test_file_apng.py | 10 ++++++++++ 2 files changed, 10 insertions(+) create mode 100644 Tests/images/apng/issue_7700.png diff --git a/Tests/images/apng/issue_7700.png b/Tests/images/apng/issue_7700.png new file mode 100644 index 0000000000000000000000000000000000000000..984254b8e5632f9f1bf148485a77bb6a141dcb4b GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`9Er&xK0ulYh#5ZjPA&jaQfUw| zkPuh{hyel)U@p%GyA42&x~Gd{NX4Aw6SvYo%ojStp!80BRioiiwh7HElNnUodZY}p z4j33RFfd-v>sQUc#0b;^GZ@51GuQzr6w`P67?6@pOK}VV(o8_Z4dze!4m2ES)C$JM dY&_!34DTjb$p7CmBOj=M!PC{xWt~$(698zJHUj_v literal 0 HcmV?d00001 diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 60d951636e8..8069d4b08bb 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -689,3 +689,13 @@ def test_different_modes_in_later_frames(mode, default_image, duplicate, tmp_pat ) with Image.open(test_file) as reloaded: assert reloaded.mode == mode + + +def test_apng_issue_7700(): + # https://github.com/python-pillow/Pillow/issues/7700 + with Image.open("Tests/images/apng/issue_7700.png") as im: + for i in range(5): + im.seek(0) + assert im.info["duration"] == 4000.0 + im.seek(1) + assert im.info["duration"] == 1000.0 From a844871c5eec479275af20ae0f06e4204174e9a6 Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Mon, 8 Jan 2024 15:18:49 -0500 Subject: [PATCH 3/6] Give apng repeated seeks test and image a more descriptive name. --- ...700.png => repeated_seeks_give_correct_info.png} | Bin Tests/test_file_apng.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename Tests/images/apng/{issue_7700.png => repeated_seeks_give_correct_info.png} (100%) diff --git a/Tests/images/apng/issue_7700.png b/Tests/images/apng/repeated_seeks_give_correct_info.png similarity index 100% rename from Tests/images/apng/issue_7700.png rename to Tests/images/apng/repeated_seeks_give_correct_info.png diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 8069d4b08bb..47d425f8b74 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -691,9 +691,9 @@ def test_different_modes_in_later_frames(mode, default_image, duplicate, tmp_pat assert reloaded.mode == mode -def test_apng_issue_7700(): +def test_apng_repeated_seeks_give_correct_info(): # https://github.com/python-pillow/Pillow/issues/7700 - with Image.open("Tests/images/apng/issue_7700.png") as im: + with Image.open("Tests/images/apng/repeated_seeks_give_correct_info.png") as im: for i in range(5): im.seek(0) assert im.info["duration"] == 4000.0 From a6051a4045354203d9fccafbe2ac620c505d9e00 Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Mon, 8 Jan 2024 15:20:24 -0500 Subject: [PATCH 4/6] Add type hints and fix some formatting for the apng repeated seeks test. --- Tests/test_file_apng.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 47d425f8b74..ea5ab41ec60 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -691,11 +691,11 @@ def test_different_modes_in_later_frames(mode, default_image, duplicate, tmp_pat assert reloaded.mode == mode -def test_apng_repeated_seeks_give_correct_info(): +def test_apng_repeated_seeks_give_correct_info() -> None: # https://github.com/python-pillow/Pillow/issues/7700 with Image.open("Tests/images/apng/repeated_seeks_give_correct_info.png") as im: for i in range(5): im.seek(0) - assert im.info["duration"] == 4000.0 + assert im.info["duration"] == 4000 im.seek(1) - assert im.info["duration"] == 1000.0 + assert im.info["duration"] == 1000 From dc6d7611e9196447aaa18305c79ee83f005f4ec3 Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Tue, 9 Jan 2024 08:55:49 -0500 Subject: [PATCH 5/6] Test apng repeated seeks 3 times instead of 5. Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_file_apng.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index ea5ab41ec60..3403322585e 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -692,9 +692,8 @@ def test_different_modes_in_later_frames(mode, default_image, duplicate, tmp_pat def test_apng_repeated_seeks_give_correct_info() -> None: - # https://github.com/python-pillow/Pillow/issues/7700 with Image.open("Tests/images/apng/repeated_seeks_give_correct_info.png") as im: - for i in range(5): + for i in range(3): im.seek(0) assert im.info["duration"] == 4000 im.seek(1) From 6f144d45b98d6c331da9fcd437542e224793b893 Mon Sep 17 00:00:00 2001 From: Erik Soma Date: Wed, 10 Jan 2024 16:03:42 -0500 Subject: [PATCH 6/6] Rename repeated seeks apng to reflect what it is rather than how it is used. --- ...ive_correct_info.png => different_durations.png} | Bin Tests/test_file_apng.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Tests/images/apng/{repeated_seeks_give_correct_info.png => different_durations.png} (100%) diff --git a/Tests/images/apng/repeated_seeks_give_correct_info.png b/Tests/images/apng/different_durations.png similarity index 100% rename from Tests/images/apng/repeated_seeks_give_correct_info.png rename to Tests/images/apng/different_durations.png diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 3403322585e..e2c4569cee5 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -692,7 +692,7 @@ def test_different_modes_in_later_frames(mode, default_image, duplicate, tmp_pat def test_apng_repeated_seeks_give_correct_info() -> None: - with Image.open("Tests/images/apng/repeated_seeks_give_correct_info.png") as im: + with Image.open("Tests/images/apng/different_durations.png") as im: for i in range(3): im.seek(0) assert im.info["duration"] == 4000