From 50bcb1dce7f56cc330ff0ce656fdceb5cc63e19b Mon Sep 17 00:00:00 2001 From: "moemansour03@gmail.com" Date: Wed, 30 Jun 2021 11:24:47 +0300 Subject: [PATCH 1/6] bpo-44539: Added quantized case checker for JPG header --- Lib/imghdr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 6e01fd857469ad..e91540f43a4d24 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -38,6 +38,8 @@ def test_jpeg(h, f): """JPEG data in JFIF or Exif format""" 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) From 235050de52d0eeab5909a13e173499958ef92ea1 Mon Sep 17 00:00:00 2001 From: "moemansour03@gmail.com" Date: Wed, 30 Jun 2021 11:36:51 +0300 Subject: [PATCH 2/6] bpo-44539: Added quantized case checker for JPG header --- .../2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst 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..0de66cd4da1c5f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst @@ -0,0 +1,27 @@ +# +# Please enter the relevant bugs.python.org issue number here: +# +.. bpo: 44539 + +# +# Uncomment one of these "section:" lines to specify which section +# this entry should go in in Misc/NEWS. +# +#.. section: Security +#.. section: Core and Builtins +.. section: Library +#.. section: Documentation +#.. section: Tests +#.. section: Build +#.. section: Windows +#.. section: macOS +#.. section: IDLE +#.. section: Tools/Demos +#.. section: C API + +# Write your Misc/NEWS entry below. It should be a simple ReST paragraph. +# Don't start with "- Issue #: " or "- bpo-: " or that sort of stuff. +########################################################################### + + +Added quantized case checker for JPG header From d375c08c75174333170b9c0c5dd34c87e69d57db Mon Sep 17 00:00:00 2001 From: mohamadmansourX <66031317+mohamadmansourX@users.noreply.github.com> Date: Wed, 30 Jun 2021 12:03:55 +0300 Subject: [PATCH 3/6] bpo-44539: Added quantized case checker for JPG header --- Lib/imghdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imghdr.py b/Lib/imghdr.py index e91540f43a4d24..93e7e3a0a0fccf 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -38,7 +38,7 @@ def test_jpeg(h, f): """JPEG data in JFIF or Exif format""" if h[6:10] in (b'JFIF', b'Exif'): return 'jpeg' - elif h[:4]==b'\xff\xd8\xff\xdb' + elif h[:4]==b'\xff\xd8\xff\xdb': return 'jpeg' tests.append(test_jpeg) From 4f5e47ab54837d6596135c11a3341c34173f994d Mon Sep 17 00:00:00 2001 From: Mohamad Mansour <66031317+mohamadmansourX@users.noreply.github.com> Date: Mon, 12 Jul 2021 11:09:30 +0300 Subject: [PATCH 4/6] Update Lib/imghdr.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Éric Araujo --- Lib/imghdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 93e7e3a0a0fccf..73adf252d828b7 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -38,7 +38,7 @@ def test_jpeg(h, f): """JPEG data in JFIF or Exif format""" if h[6:10] in (b'JFIF', b'Exif'): return 'jpeg' - elif h[:4]==b'\xff\xd8\xff\xdb': + elif h[:4] == b'\xff\xd8\xff\xdb': return 'jpeg' tests.append(test_jpeg) From ba2ce7a291ef13596fd47c262ebef04f24105cd0 Mon Sep 17 00:00:00 2001 From: Mohamad Mansour <66031317+mohamadmansourX@users.noreply.github.com> Date: Mon, 12 Jul 2021 11:16:46 +0300 Subject: [PATCH 5/6] Update 2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst --- .../2021-06-30-11-34-35.bpo-44539.nP0Xi4.rst | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) 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 index 0de66cd4da1c5f..8d660e626579ec 100644 --- 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 @@ -1,27 +1,8 @@ -# -# Please enter the relevant bugs.python.org issue number here: -# .. bpo: 44539 -# -# Uncomment one of these "section:" lines to specify which section -# this entry should go in in Misc/NEWS. -# -#.. section: Security -#.. section: Core and Builtins .. section: Library -#.. section: Documentation -#.. section: Tests -#.. section: Build -#.. section: Windows -#.. section: macOS -#.. section: IDLE -#.. section: Tools/Demos -#.. section: C API -# Write your Misc/NEWS entry below. It should be a simple ReST paragraph. -# Don't start with "- Issue #: " or "- bpo-: " or that sort of stuff. -########################################################################### -Added quantized case checker for JPG header + +Added quantized case checker for JPG headers in ``Imghdr.what``. Previously, it was failing to identify quantized cases. From 1417d1f57b9787f79dcafade259cb5288a85eb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Tue, 20 Jul 2021 20:06:51 +0200 Subject: [PATCH 6/6] Review updates --- Lib/imghdr.py | 2 +- 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 | 9 +-------- 4 files changed, 3 insertions(+), 9 deletions(-) create mode 100644 Lib/test/imghdrdata/python-raw.jpg diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 73adf252d828b7..afcb67772ee9a9 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -35,7 +35,7 @@ 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': 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 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 index 8d660e626579ec..f5e831afce8358 100644 --- 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 @@ -1,8 +1 @@ -.. bpo: 44539 - -.. section: Library - - - - -Added quantized case checker for JPG headers in ``Imghdr.what``. Previously, it was failing to identify quantized cases. +Added support for recognizing JPEG files without JFIF or Exif markers.