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
Improved handling of PPM header #5121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just a random contributor so I don't dare to "Approve", but apart from the minor notes I added this looks good to me. 👍
I hurried to push and forgot to lint and a |
- add test for maxcolors; - extend coverage for wrong magic number; - fix linting.
- ...so as not to reject "2,147,483,647" (2 ** 31 - 1); - reword exception message.
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
|
||
with pytest.raises(ValueError): | ||
with Image.open(path): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite on board with this one. The idea here is that b"\x00" is not caught by
Pillow/src/PIL/PpmImagePlugin.py
Lines 57 to 58 in 92c26a7
if c > b"\x79": | |
raise ValueError("Expected ASCII value, found binary") |
even though \x00 is not greater than \x79, and only for it to be raised as a different ValueError later when it turns out that b"128\x00" is not an integer.
There isn't a valid scenario where the token/magic needs to be something other than a number or a letter. I've pushed a commit to change this test into a check that a ValueError is raised when a token is not an integer.
Addresses #5104. That discussion didn't get any replies, so I decided to open this PR to make my intentions more explicit.
Changes proposed in this pull request: