Do not update GIF frame position until local image is found #6219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6320
#6207 (reply in thread) points out that if a GIF file contains a comment block after the last image, then Pillow calculates
n_frames
incorrectly, thinking there is 1 more frame than there really is.Why does this happen?
n_frames
seeks through the image until it hits anEOFError
.Pillow/src/PIL/GifImagePlugin.py
Lines 112 to 121 in c456aec
At the moment, once GifImagePlugin determines that there is more data in the file, it updates the frame position.
Pillow/src/PIL/GifImagePlugin.py
Lines 182 to 186 in c456aec
It doesn't consider that an
EOFError
might still be raised if the local image is not found.Pillow/src/PIL/GifImagePlugin.py
Lines 283 to 285 in c456aec
where
interlace
is only set when reading the local image.So this PR just moves
self.__frame = frame
after that lastEOFError
.The test image was created using a modified Pillow.