Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tests/images/multiple_comments.gif
Loading
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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