-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-37629: Update judgment method for jpeg. #15955
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
base: main
Are you sure you want to change the base?
Conversation
Changed to test method for jpeg based on file signature. https://en.wikipedia.org/wiki/List_of_file_signatures
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
add one image to verify jpeg detection code.
42c5c43
to
c7e4729
Compare
Don’t add a jpeg file, create a fake jpeg file during the test and you remove it after. |
Excuse me. |
Yep, open a binary file and store the magic number in the file, or the header. |
Lib/imghdr.py
Outdated
@@ -36,7 +36,7 @@ def what(file, h=None): | |||
|
|||
def test_jpeg(h, f): | |||
"""JPEG data in JFIF or Exif format""" | |||
if h[6:10] in (b'JFIF', b'Exif'): | |||
if h[:2] == b'\xff\xd8': |
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.
And what’s the behaviour with the existing files?
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.
It returns True only for python.jpg
and False otherwise.
This is the same as the previous code.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
The magic number I'm focusing on is |
store it into a file, but I would like to be sure that all the tests pass with any jpg file. |
I've already tested with hundreds of randomly prepared jpg files, but there is no mistake. |
I have made the requested changes; please review again |
Thanks for making the requested changes! @matrixise: please review the changes made to this pull request. |
@matrixise Could you check for changes? |
The following commit authors need to sign the Contributor License Agreement: |
Changed to judgment method for jpeg based on file signature.
https://en.wikipedia.org/wiki/List_of_file_signatures
https://bugs.python.org/issue37629