Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate multiple GIF comment blocks with newlines #6294

Merged
merged 2 commits into from May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/multiple_comments.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Tests/test_file_gif.py
Expand Up @@ -813,6 +813,12 @@ def test_zero_comment_subblocks():
assert_image_equal_tofile(im, TEST_GIF)


def test_read_multiple_comment_blocks():
with Image.open("Tests/images/multiple_comments.gif") as im:
# Multiple comment blocks in a frame are separated not concatenated
assert im.info["comment"] == b"Test comment 1\nTest comment 2"


def test_version(tmp_path):
out = str(tmp_path / "temp.gif")

Expand Down
14 changes: 10 additions & 4 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -228,12 +228,18 @@ def _seek(self, frame, update_image=True):
#
# comment extension
#
comment = b""

# Collect one comment block
while block:
if "comment" in info:
info["comment"] += block
else:
info["comment"] = block
comment += block
block = self.data()

if "comment" in info:
# If multiple comment blocks in frame, separate with \n
info["comment"] += b"\n" + comment
else:
info["comment"] = comment
s = None
continue
elif s[0] == 255:
Expand Down