Skip to content

Commit

Permalink
bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (
Browse files Browse the repository at this point in the history
pythonGH-26964)

Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Éric Araujo <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
  • Loading branch information
4 people authored Jul 20, 2021
1 parent 6564656 commit 3b56b3b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Lib/imghdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def what(file, h=None):
tests = []

def test_jpeg(h, f):
"""JPEG data in JFIF or Exif format"""
"""JPEG data with JFIF or Exif markers; and raw JPEG"""
if h[6:10] in (b'JFIF', b'Exif'):
return 'jpeg'
elif h[:4] == b'\xff\xd8\xff\xdb':
return 'jpeg'

tests.append(test_jpeg)

Expand Down
Binary file added Lib/test/imghdrdata/python-raw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Lib/test/test_imghdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
('python.pgm', 'pgm'),
('python.pbm', 'pbm'),
('python.jpg', 'jpeg'),
('python-raw.jpg', 'jpeg'), # raw JPEG without JFIF/EXIF markers
('python.ras', 'rast'),
('python.sgi', 'rgb'),
('python.tiff', 'tiff'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for recognizing JPEG files without JFIF or Exif markers.

0 comments on commit 3b56b3b

Please sign in to comment.