[Python-checkins] bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964)

ambv webhook-mailer at python.org
Tue Jul 20 14:57:05 EDT 2021


https://github.com/python/cpython/commit/3b56b3b97d91e2b412ce1b2bcaddcd43ef3d223b
commit: 3b56b3b97d91e2b412ce1b2bcaddcd43ef3d223b
branch: main
author: Mohamad Mansour <66031317+mohamadmansourX at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-20T20:56:57+02:00
summary:

bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964)

Co-authored-by: moemansour03 at gmail.com <m.mansour at tecfrac.com>
Co-authored-by: Éric Araujo <merwok at netwok.org>
Co-authored-by: Łukasz Langa <lukasz at langa.pl>

files:
A Lib/test/imghdrdata/python-raw.jpg
A Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst
M Lib/imghdr.py
M Lib/test/test_imghdr.py

diff --git a/Lib/imghdr.py b/Lib/imghdr.py
index 6e01fd857469ad..afcb67772ee9a9 100644
--- a/Lib/imghdr.py
+++ b/Lib/imghdr.py
@@ -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)
 
diff --git a/Lib/test/imghdrdata/python-raw.jpg b/Lib/test/imghdrdata/python-raw.jpg
new file mode 100644
index 00000000000000..11940b3410ddf0
Binary files /dev/null and b/Lib/test/imghdrdata/python-raw.jpg differ
diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py
index b2d1fc8322a038..ca0a0b23c3cf1a 100644
--- a/Lib/test/test_imghdr.py
+++ b/Lib/test/test_imghdr.py
@@ -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'),
diff --git a/Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst b/Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst
new file mode 100644
index 00000000000000..f5e831afce8358
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst
@@ -0,0 +1 @@
+Added support for recognizing JPEG files without JFIF or Exif markers.



More information about the Python-checkins mailing list