Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recognizing JPEG files without JFIF or Exif markers #88705

Closed
mohamadmansourX mannequin opened this issue Jun 30, 2021 · 4 comments
Closed

Support recognizing JPEG files without JFIF or Exif markers #88705

mohamadmansourX mannequin opened this issue Jun 30, 2021 · 4 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mohamadmansourX
Copy link
Mannequin

mohamadmansourX mannequin commented Jun 30, 2021

BPO 44539
Nosy @ambv, @fbidu, @mohamadmansourX
PRs
  • bpo-44539: Support recognizing JPEG files without JFIF or Exif markers #26964
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-20.18:57:30.296>
    created_at = <Date 2021-06-30.08:12:46.419>
    labels = ['type-feature', 'library', '3.11']
    title = 'Support recognizing JPEG files without JFIF or Exif markers'
    updated_at = <Date 2021-07-20.18:58:16.520>
    user = 'https://github.com/mohamadmansourX'

    bugs.python.org fields:

    activity = <Date 2021-07-20.18:58:16.520>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-20.18:57:30.296>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2021-06-30.08:12:46.419>
    creator = 'mohamadmansourx'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44539
    keywords = ['patch']
    message_count = 4.0
    messages = ['396771', '397891', '397899', '397900']
    nosy_count = 3.0
    nosy_names = ['lukasz.langa', 'fbidu', 'mohamadmansourx']
    pr_nums = ['26964']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44539'
    versions = ['Python 3.11']

    @mohamadmansourX
    Copy link
    Mannequin Author

    mohamadmansourX mannequin commented Jun 30, 2021

    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.
    Reference:
    https://www.digicamsoft.com/itu/itu-t81-36.html
    https://web.archive.org/web/20120403212223/http://class.ee.iastate.edu/ee528/Reading%20material/JPEG_File_Format.pdf

    @mohamadmansourX mohamadmansourX mannequin added topic-C-API 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-feature A feature request or enhancement stdlib Python modules in the Lib dir and removed topic-C-API labels Jun 30, 2021
    @merwok merwok removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Jul 9, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    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:

    https://en.wikipedia.org/wiki/List_of_file_signatures

    @ambv ambv changed the title Imghdr JPG Quantized Support recognizing JPEG files without JFIF or Exif markers Jul 20, 2021
    @ambv ambv changed the title Imghdr JPG Quantized Support recognizing JPEG files without JFIF or Exif markers Jul 20, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    New changeset 3b56b3b by Mohamad Mansour in branch 'main':
    bpo-44539: Support recognizing JPEG files without JFIF or Exif markers (GH-26964)
    3b56b3b

    @ambv ambv closed this as completed Jul 20, 2021
    @ambv ambv closed this as completed Jul 20, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    Thanks, Mohamad! ✨ 🍰 ✨

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants