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

Always use GIF89a for comments #6292

Merged
merged 4 commits into from May 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion Tests/test_file_gif.py
Expand Up @@ -804,8 +804,9 @@ def test_comment_over_255(tmp_path):
im.info["comment"] = comment
im.save(out)
with Image.open(out) as reread:

assert reread.info["comment"] == comment
# Test that GIF89a is used for long comment
assert reread.info["version"] == b"GIF89a"


def test_zero_comment_subblocks():
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GifImagePlugin.py
Expand Up @@ -915,7 +915,7 @@ def _get_global_header(im, info):
for extensionKey in ["transparency", "duration", "loop", "comment"]:
if info and extensionKey in info:
if (extensionKey == "duration" and info[extensionKey] == 0) or (
extensionKey == "comment" and not (1 <= len(info[extensionKey]) <= 255)
extensionKey == "comment" and len(info[extensionKey]) == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extensionKey == "comment" and len(info[extensionKey]) == 0
extensionKey == "comment" and info[extensionKey]

This seems simpler to me?

Copy link
Contributor Author

@raygard raygard May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radarhere, thank you for reviewing my PR.

The test needs to determine that info[comment] is an empty string to keep version as 87a. Your suggestion info[extensionKey] does the opposite. I was attempting to extrapolate from not (1 <= len(info[extensionKey]) <= 255) (which originated with PR #1896 but was superseded by PR #3479) to retain the length test. I think it probably could be info[extensionKey] == "" or even not info[extensionKey]. The 255 was there to begin with, I think, to fit with the maximum length of the single data block that was allowed before PR #3479.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - I meant not info[extensionKey]. That was just a mistake on my part.

):
continue
version = b"89a"
Expand Down