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

Conversation

raygard
Copy link
Contributor

@raygard raygard commented May 13, 2022

Fix bug that allows GIFs with long comments to be written as GIF87a.

Fixes #6291 .

Changes proposed in this pull request:

  • Change version feature test in _get_global_header() to use GIF89a for long comments.
  • Add test in test_comment_over_255() to check this.

Fix bug that allows GIFs with long comments to be written as GIF87a.
@@ -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.

@radarhere radarhere changed the title Always use GIF89a for long comments Always use GIF89a for comments May 18, 2022
@radarhere
Copy link
Member

This forces GIF89a for all comments, not just "long comments". So wouldn't it be more straightforward to modify test_comment, rather than test_comment_over_255?

@raygard
Copy link
Contributor Author

raygard commented May 18, 2022

@radarhere,

This forces GIF89a for all comments, not just "long comments". So wouldn't it be more straightforward to modify test_comment, rather than test_comment_over_255?

Pillow already uses GIF89a for shorter comments, so adding assert reread.info["version"] == b"GIF89a" in test_comment would not show that the PR actually fixed anything (but it couldn't hurt to add that in test_comment too). You have more experience than I with automated unit tests, but I recall you telling me that one reason for these tests is to prevent regressions, so (as I understand) a test should fail with the old code and pass with the new code. I tried to do that with this and also with test_read_multiple_comments and test_write_comment in my other recent PRs. (OTOH test_write_no_comment tests that an empty comment="" arg to .save() will leave no comment at all, and that will work before and after my PRs; I just thought it would be a good thing to have a test for it.)

@radarhere
Copy link
Member

Ok, thanks. That's perfectly fair.

@radarhere
Copy link
Member

radarhere commented May 20, 2022

I've created https://github.com/raygard/Pillow/pull/1 with a suggestion from me, to add the check to test_comment() as well, and a modified copy of your suggestion from #6291 (comment) to simplify the version check.

@radarhere radarhere merged commit 2072a52 into python-pillow:main May 21, 2022
@raygard raygard deleted the comment_use_gif89a branch May 24, 2022 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GIF files with comments must be GIF89a
2 participants