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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/imghdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def what(file, h=None):
tests = []

def test_jpeg(h, f):
"""JPEG data in JFIF or Exif format"""
if h[6:10] in (b'JFIF', b'Exif'):
"""JPEG data"""
if h.startswith(b'\xff\xd8'):
return 'jpeg'

tests.append(test_jpeg)
Expand Down
Binary file modified Lib/test/imghdrdata/python.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Lib/test/test_imghdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_bad_args(self):
imghdr.what()
with self.assertRaises(AttributeError):
imghdr.what(None)
with self.assertRaises(TypeError):
with self.assertRaises(AttributeError):
imghdr.what(self.testfile, 1)
with self.assertRaises(AttributeError):
imghdr.what(os.fsencode(self.testfile))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changed to judgment method for jpeg based on file signature.
ref: https://en.wikipedia.org/wiki/List_of_file_signatures