From 3b56b3b97d91e2b412ce1b2bcaddcd43ef3d223b Mon Sep 17 00:00:00 2001 From: Mohamad Mansour <66031317+mohamadmansourX@users.noreply.github.com> Date: Tue, 20 Jul 2021 21:56:57 +0300 Subject: [PATCH] bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: moemansour03@gmail.com Co-authored-by: Éric Araujo Co-authored-by: Łukasz Langa --- Lib/imghdr.py | 4 +++- Lib/test/imghdrdata/python-raw.jpg | Bin 0 -> 525 bytes Lib/test/test_imghdr.py | 1 + .../2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Lib/test/imghdrdata/python-raw.jpg create mode 100644 Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 6e01fd85746..afcb67772ee 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 0000000000000000000000000000000000000000..11940b3410ddf052a996d705006236172e153c25 GIT binary patch literal 525 zcmex=y%&ai23_z|RGYc!5B7=~js90j-!~eG!c$gW1&R`Z~uxAiib}37`_~0{Pp(|5m zJ_{y4QBB>qE9ySbOP zKJvD_{#YsalT_xtD}`PbTbf>YcWM=8%AM6!wEp;hr&P(BcMGFR`>uMdNsVspZfvbq z)SQvNGJDES&s6`NCt5WHy&JVYRNee!(@+<>kM~>BLWeUip3Sn2+3vjgdR1z~#+!kP z9s5&uT>f}CgGKYeg@3zkm>$@Kuy5IWvpVFN`tQ8^QxZg)l7xGA1kKPeXYDMiOn73{ ZnSZ#cZ+TG9D}~;D6_WDoYwQ2t1OUankdy!b literal 0 HcmV?d00001 diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py index b2d1fc8322a..ca0a0b23c3c 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 00000000000..f5e831afce8 --- /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.