]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964)
authorMohamad Mansour <66031317+mohamadmansourX@users.noreply.github.com>
Tue, 20 Jul 2021 18:56:57 +0000 (21:56 +0300)
committerGitHub <noreply@github.com>
Tue, 20 Jul 2021 18:56:57 +0000 (20:56 +0200)
Co-authored-by: moemansour03@gmail.com <m.mansour@tecfrac.com>
Co-authored-by: Éric Araujo <merwok@netwok.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Lib/imghdr.py
Lib/test/imghdrdata/python-raw.jpg [new file with mode: 0644]
Lib/test/test_imghdr.py
Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst [new file with mode: 0644]

index 6e01fd857469ad89e597009d8c1aa093f2f90313..afcb67772ee9a901309cd61c3323b9fe284f8780 100644 (file)
@@ -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 (file)
index 0000000..11940b3
Binary files /dev/null and b/Lib/test/imghdrdata/python-raw.jpg differ
index b2d1fc8322a038c3f6f31220289a3ecbf20ada04..ca0a0b23c3cf1a45ba37a8fdcc70478ab638a52d 100644 (file)
@@ -16,6 +16,7 @@ TEST_FILES = (
     ('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 (file)
index 0000000..f5e831a
--- /dev/null
@@ -0,0 +1 @@
+Added support for recognizing JPEG files without JFIF or Exif markers.