From c8118438ae4ad477f8b4f7c969e2c16b892a0d8f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 16 Apr 2022 17:07:39 +1000 Subject: [PATCH] Do not update frame position until local image is found --- Tests/images/comment_after_last_frame.gif | Bin 0 -> 1625 bytes Tests/test_file_gif.py | 27 ++++++++++++++-------- src/PIL/GifImagePlugin.py | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 Tests/images/comment_after_last_frame.gif diff --git a/Tests/images/comment_after_last_frame.gif b/Tests/images/comment_after_last_frame.gif new file mode 100644 index 0000000000000000000000000000000000000000..9f5c7b8da471dfe3f29d4578c83d145b81dc69dc GIT binary patch literal 1625 zcmZ?wbhEHbWMp7uXlED&qaiS&LqPFAx1VcBu(M-;tC5}oGb1AdgAOP_K-q(VgN1>S jg@r-!AA53sZfRu-WQPD|-mnG$b$}1h literal 0 HcmV?d00001 diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index dffd1006f2f..d177520e2cb 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -341,16 +341,23 @@ def test_seek_rewind(): assert_image_equal(im, expected) -def test_n_frames(): - for path, n_frames in [[TEST_GIF, 1], ["Tests/images/iss634.gif", 42]]: - # Test is_animated before n_frames - with Image.open(path) as im: - assert im.is_animated == (n_frames != 1) - - # Test is_animated after n_frames - with Image.open(path) as im: - assert im.n_frames == n_frames - assert im.is_animated == (n_frames != 1) +@pytest.mark.parametrize( + "path, n_frames", + ( + (TEST_GIF, 1), + ("Tests/images/comment_after_last_frame.gif", 2), + ("Tests/images/iss634.gif", 42), + ), +) +def test_n_frames(path, n_frames): + # Test is_animated before n_frames + with Image.open(path) as im: + assert im.is_animated == (n_frames != 1) + + # Test is_animated after n_frames + with Image.open(path) as im: + assert im.n_frames == n_frames + assert im.is_animated == (n_frames != 1) def test_no_change(): diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index b798bb96991..5c8016839d6 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -183,8 +183,6 @@ def _seek(self, frame, update_image=True): if not s or s == b";": raise EOFError - self.__frame = frame - self.tile = [] palette = None @@ -283,6 +281,8 @@ def _seek(self, frame, update_image=True): if interlace is None: # self.__fp = None raise EOFError + + self.__frame = frame if not update_image: return