Skip to content

fix(mime-bytes): detect HEIC/HEIF instead of misidentifying as MP4#1158

Merged
pyramation merged 1 commit into
mainfrom
fix/heic-detection
May 14, 2026
Merged

fix(mime-bytes): detect HEIC/HEIF instead of misidentifying as MP4#1158
pyramation merged 1 commit into
mainfrom
fix/heic-detection

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

Fixes #967. HEIC and HEIF images were misidentified as video/mp4 because all three formats share the ISO Base Media File Format ftyp container prefix. The mp4 entry (4 magic bytes) appeared before heic/heif (8 magic bytes) in the registry, so the shorter prefix matched first.

The fix sorts this.fileTypes by magicBytes.length descending in the FileTypeDetector constructor, ensuring longer (more specific) signatures are checked before shorter prefix patterns.

Review & Testing Checklist for Human

  • Verify with a real .heic photo from an iPhone that detection returns image/heic instead of video/mp4
  • Confirm that actual MP4 video files (e.g. with isom brand) still detect correctly as video/mp4

Notes

  • The sort is stable (JS spec), so entries with identical magicBytes.length retain their original order.
  • Tests added for both HEIC (ftypheic brand) and HEIF (ftypmif1 brand) buffers, plus the existing MP4 (ftypisom) test continues to pass.

Link to Devin session: https://app.devin.ai/sessions/1db29f3c8a46434c99001ddcb701cc12
Requested by: @pyramation

Sort fileTypes by magicBytes length descending so that longer (more
specific) magic byte patterns are checked before shorter prefixes.
This fixes HEIC and HEIF images being misidentified as video/mp4
because both formats share the ISO Base Media File Format 'ftyp'
container prefix.

Closes #967
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 30b1ffc into main May 14, 2026
37 checks passed
@pyramation pyramation deleted the fix/heic-detection branch May 14, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mime-bytes identifies HEIF image as video/mp4

1 participant