Title: Support recognizing JPEG files without JFIF or Exif markers
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fbidu, lukasz.langa, mohamadmansourx
Priority: normal Keywords: patch

Created on 2021-06-30 08:12 by mohamadmansourx, last changed 2021-07-20 18:58 by lukasz.langa. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26964 merged mohamadmansourx, 2021-06-30 08:51
Messages (4)
msg396771 - (view) Author: Mohamad Mansour (mohamadmansourx) * Date: 2021-06-30 08:12
Previous method to check JPG images was using the following command (h[6:10] in (b'JFIF', b'Exif'))
However, its not always the case as some might start with b'\xff\xd8\xff\xdb' header.
msg397891 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-20 18:13
When JFIF and Exif markers are removed, what we're left with is a "raw" JPEG file.

I added a raw equivalent of Lib/test/imghdrdata/python.jpg by running:

$ exiftool -all= python.jpg -o python-raw.jpg

Mohamad's patch correctly adds support for such files. In fact, browsing through how other languages do this, it seems like the FF D8 FF DB sequence is a relatively popular "magic sequence". It's even listed in this Wikipedia page:
msg397899 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-20 18:57
New changeset 3b56b3b97d91e2b412ce1b2bcaddcd43ef3d223b by Mohamad Mansour in branch 'main':
bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964)
msg397900 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-20 18:58
Thanks, Mohamad! ✨ 🍰 ✨
Date User Action Args
2021-07-20 18:58:16lukasz.langasetmessages: + msg397900
2021-07-20 18:57:30lukasz.langasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-20 18:57:04lukasz.langasetmessages: + msg397899
2021-07-20 18:13:04lukasz.langasetnosy: + lukasz.langa

messages: + msg397891
title: Imghdr JPG Quantized -> Support recognizing JPEG files without JFIF or Exif markers
2021-07-09 18:50:26eric.araujosetversions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-07-03 11:40:38fbidusetnosy: + fbidu
2021-06-30 08:51:23mohamadmansourxsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25529
2021-06-30 08:28:26mohamadmansourxsetcomponents: + Library (Lib), - C API
2021-06-30 08:12:46mohamadmansourxcreate