Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

derodero24
Copy link

@derodero24 derodero24 commented Sep 11, 2019

Changed to judgment method for jpeg based on file signature.
https://en.wikipedia.org/wiki/List_of_file_signatures

https://bugs.python.org/issue37629

Changed to test method for jpeg based on file signature.
https://en.wikipedia.org/wiki/List_of_file_signatures
@the-knights-who-say-ni
Copy link

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 username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@derodero24

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!

@matrixise
Copy link
Member

Don’t add a jpeg file, create a fake jpeg file during the test and you remove it after.

@derodero24
Copy link
Author

Don’t add a jpeg file, create a fake jpeg file during the test and you remove it after.

Excuse me.
I couldn't find the method creating a fake jpeg file.
Could you tell me where it is?
Thanks.

@matrixise
Copy link
Member

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':
Copy link
Member

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?

Copy link
Author

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.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@derodero24
Copy link
Author

Yep, open a binary file and store the magic number in the file, or the header.

The magic number I'm focusing on is \xff\xd8.
How should I store this?

@matrixise
Copy link
Member

store it into a file, but I would like to be sure that all the tests pass with any jpg file.

@derodero24
Copy link
Author

derodero24 commented Sep 14, 2019

I've already tested with hundreds of randomly prepared jpg files, but there is no mistake.
At least it should be better than current code.

@derodero24
Copy link
Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@matrixise: please review the changes made to this pull request.

@derodero24
Copy link
Author

@matrixise Could you check for changes?

@csabella csabella requested review from matrixise and removed request for matrixise May 28, 2020 22:57
@python-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants