Skip to content

fix(utils): check the whole MPEG and ADTS frame header before detecting audio - #298

Merged
donghaoren merged 1 commit into
apple:mainfrom
Manishram-ai:fix/media-mpeg-header-check
Nov 6, 2026
Merged

donghaoren merged 1 commit into
apple:mainfrom
Manishram-ai:fix/media-mpeg-header-check

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Follow-up to #297. detectAudioMimeType treats anything that starts with an 11-bit sync word as an MP3 or AAC frame. 0xFF padding (FF FF FF) and other binary data like FF E1 00 pass that check, so the viewer's valueKind shows an audio player for them and never looks at the path's file extension.

This uses the same header check the backend got in #297. ADTS needs the 12-bit sync word and a valid sampling frequency index. MPEG audio can't use the reserved version, layer, bitrate or sample rate values.

Testing:

  • A new test in packages/utils/test/media.test.js fails on main and passes with the fix. All 124 utils tests pass.
  • MP3s made with ffmpeg at 44.1, 22.05 and 8 kHz, an MP2 file and an ADTS AAC file are still detected as audio/mpeg and audio/aac.
  • tsc --build and Prettier are clean.

@donghaoren
donghaoren merged commit 152e5c5 into apple:main Nov 6, 2026
8 checks passed
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.

2 participants