Skip to content

Media: Accept audio files stored in an MP4 container detected as video/mp4 - #13156

Closed
sanketio wants to merge 9 commits into
WordPress:trunkfrom
sanketio:fix/audio-mime-video-container-46544
Closed

sanketio wants to merge 9 commits into
WordPress:trunkfrom
sanketio:fix/audio-mime-video-container-46544

Conversation

@sanketio

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/46544

Problem

Uploading an audio file whose real MIME type doesn't share the same major type as its extension is rejected with "Sorry, you are not allowed to upload this file type." The common real-world case is audio stored in an MP4/ISO-BMFF container — .m4a/.m4b, and some .mp3 files produced by mobile recorders — which fileinfo detects as video/mp4, while the extension maps to audio/mpeg.

In wp_check_filetype_and_ext(), the audio/* / video/* branch forgives sub-type mismatches but still requires the major type to match, so audio/mpeg (from the extension) vs video/mp4 (from finfo) fails and the file is rejected.

Change

Add a small, curated allow-list for known audio-in-MP4-container confusions inside that branch, mirroring the existing special-casing for text/csv and text/rtf. All three affected extensions (m4a, m4b, mp3) map to audio/mpeg, so the case collapses to a single entry:

$cross_container_types = array(
    'audio/mpeg' => array( 'video/mp4' ),
);

The check stays strict for every other combination. The application/octet-stream variant from the original report already passes today via the $nonspecific_types branch, so this targets only the remaining video/mp4 case.

Security: the worst case is a genuine MP4 video uploaded as .m4a being treated as audio/mpeg — both are allowed media types served as downloads, so no new upload vector is opened.

Testing instructions

  1. Attempt to upload an audio file that fileinfo reports as video/mp4 (e.g. an .m4a from a phone recorder, or any MP4 container renamed to .m4a) via Media → Add New.
  2. Before this change: the upload fails with "Sorry, you are not allowed to upload this file type."
  3. After this change: the file uploads and appears in the Media Library as audio (audio/mpeg).

Automated coverage: a new case in the data_wp_check_filetype_and_ext provider uploads a fixture detected as video/mp4 and asserts it resolves to ext = m4a, type = audio/mpeg. The full Tests_Functions suite passes on single and multisite.

Use of AI Tools

  • AI assistance: Yes
  • Tool(s): Claude Code
  • Model(s): Claude Opus 4.8
  • Used for: investigating the root cause, drafting the fix and unit test, and verifying via automated tests and a live Media Library upload.

@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sanketparmar, joedolson, robertbpugh.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@robertbpugh robertbpugh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also allow video/3gpp? I tested the detection side with PHP 8.5's fileinfo on a two-second AAC file, saved with different container brands:

  • M4A brand: audio/x-m4a, which already passes
  • isom and mp42: video/mp4, which this PR fixes
  • 3gp4, 3gp5 and 3gp6: video/3gpp, which still fails the major-type check with this change

The iPhone recording behind our WordPress.com report had a 3GP brand, so it would still be rejected. Could you add a 3GP-branded fixture next to audio-in-video-container.m4a as well?

Comment thread src/wp-includes/functions.php Resolved
@joedolson

Copy link
Copy Markdown
Contributor

I've had trouble generating a 3gp fixture that actually fails to upload; @robertbpugh do you have a file that would be a good test?

@robertbpugh

Copy link
Copy Markdown

The attached zip has audio-only-3gp4.m4a: three seconds of AAC audio in an MP4 container with the 3gp4 brand. PHP's finfo reads it as video/3gpp on both 8.2 and 8.5.

On trunk (the 7.2-beta4-65334 nightly) it fails with "Sorry, you are not allowed to upload this file type." With this PR it uploads as audio/mpeg.

A file named .3gp won't reproduce it, since that extension already maps to video/3gpp. The same audio saved as audio-only.3gp (also in the zip) uploads fine on trunk.

To make your own:

ffmpeg -f lavfi -i "sine=frequency=440:duration=3" -c:a aac -f mp4 -brand 3gp4 audio-only-3gp4.m4a

audio-only-3gp4-fixture.zip

wporg-sync pushed a commit that referenced this pull request Nov 8, 2026
Some audio files can legitimately have real mime types that map to video. This causes an upload failure because of the mismatched subtype to primary type. 

Add support for .m4a extensions that are detected as video mime types. Subtypes were already allowed in `wp_check_filetype_and_ext()`, but the mismatched major type caused an upload failure.

Developed in #13156.

Props soleo, subrataemfluence, ironprogrammer, joedolson, sanketparmar, arkaprabhachowdhury, andrewssanya, robertbpugh.
Fixes #46544.

git-svn-id: https://develop.svn.wordpress.org/trunk@65340 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65340
GitHub commit: 80d0290

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 8, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 8, 2026
Some audio files can legitimately have real mime types that map to video. This causes an upload failure because of the mismatched subtype to primary type. 

Add support for .m4a extensions that are detected as video mime types. Subtypes were already allowed in `wp_check_filetype_and_ext()`, but the mismatched major type caused an upload failure.

Developed in WordPress/wordpress-develop#13156.

Props soleo, subrataemfluence, ironprogrammer, joedolson, sanketparmar, arkaprabhachowdhury, andrewssanya, robertbpugh.
Fixes #46544.
Built from https://develop.svn.wordpress.org/trunk@65340


git-svn-id: http://core.svn.wordpress.org/trunk@64480 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants