Skip to content

fix: recognize .heic and .heif as images - #623

Closed
Taiwudao wants to merge 1 commit into
pre-commit:mainfrom
Taiwudao:fix/heic-heif-image
Closed

Taiwudao wants to merge 1 commit into
pre-commit:mainfrom
Taiwudao:fix/heic-heif-image

Conversation

@Taiwudao

Copy link
Copy Markdown

Neither .heic nor .heif is in the extension map, so both fall through to the default text tag:

>>> from identify import identify
>>> identify.tags_from_filename('photo.heic')
{'executable', 'file', 'text'}

HEIC is the default camera format on recent iPhones, and tagging it as text means anything gated on the text tag will treat photo data as text. In pre-commit that is end-of-file-fixer, trailing-whitespace, mixed-line-ending and friends - they will happily rewrite binary image data.

Compare .avif, .webp, .tiff, which are all present as {'binary', 'image', ...}.

Change

     'hcl': {'text', 'hcl'},
+    'heic': {'binary', 'image', 'heic'},
+    'heif': {'binary', 'image', 'heif'},

Tests

Two cases added to the filename table in tests/identify_test.py:

('f.heic', {'binary', 'image', 'heic'}),
('f.HEIF', {'binary', 'image', 'heif'}),
pytest tests -k "heic or HEIF or JPG" 6 passed
full suite 545 passed, 12 failed
reverse check without the map entries the two new cases fail (14 failed vs 12)

The 12 remaining failures are pre-existing on this Windows machine (missing license dependency and the executable-bit tests), and the count is identical with and without this change.

Neither extension was in the extension map, so they fell through to the
default text tag:

    >>> tags_from_filename('photo.heic')
    {'file', 'executable', 'text'}

HEIC is the default camera format on recent iPhones, and describing it as
text means hooks that process text files (pre-commit's end-of-file-fixer,
trailing-whitespace, and anything else gated on the text tag) will happily
rewrite binary photo data.

Add both next to the other image formats.
@asottile

Copy link
Copy Markdown
Member

we don't accept slop

@asottile asottile closed this Nov 21, 2026
@pre-commit pre-commit locked as spam and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants