WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#46544 new defect (bug)

mp3 file with different file mime type and content type when uploading should not be rejected

Reported by: soleo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 5.1
Component: Media Keywords: needs-patch has-screenshots
Focuses: Cc:
PR Number:

Description

<?php
$files = [
    'recording6021333337014136895.mp3',
    'SampleAudio_0.7mb.mp3',
    'to_test_on_timby_voice_note.m4a'
];
if (  extension_loaded( 'fileinfo' ) ) {
    foreach ($files as $file ) {
        $finfo     = finfo_open( FILEINFO_MIME_TYPE );
        $real_mime = finfo_file( $finfo, $file );
        finfo_close( $finfo );
        echo "$file $real_mime\r\n";
    }
}

Results:

recording6021333337014136895.mp3 video/mp4
SampleAudio_0.7mb.mp3 audio/mpeg
to_test_on_timby_voice_note.m4a application/octet-stream

All the files are valid, but recording6021333337014136895.mp3 and to_test_on_timby_voice_note.m4a because of the mime type.

https://github.com/WordPress/WordPress/commit/3af00578e46efa3b59fb8ed9f4177d632a123a2e is the commit which introduces this issue

Attachments (4)

recording6021333337014136895.mp3 (37.0 KB) - added by soleo 7 months ago.
Recording from phone
to_test_on_timby_voice_note.m4a (130.1 KB) - added by soleo 7 months ago.
Another recording
SampleAudio_0.7mb.mp3 (708.2 KB) - added by soleo 7 months ago.
Regular test sample audio
xj.m4a (295.9 KB) - added by soleo 7 months ago.
Another example for m4a audio file

Download all attachments as: .zip

Change History (7)

@soleo
7 months ago

Recording from phone

@soleo
7 months ago

Another recording

@soleo
7 months ago

Regular test sample audio

#1 follow-up: @subrataemfluence
7 months ago

Welcome to trac and thanks for the report!

recording6021333337014136895.mp3 video/mp4
to_test_on_timby_voice_note.m4a application/octet-stream

The issue with the above files should ideally be fixed by adding right associations in wp_get_mime_types function inside wp_includes/functions.php file.

'mp3'   => 'video/mp4',
'm4a'   => 'application/octet-stream',

The issue with recording6021333337014136895.mp3 video/mp4 has actually resolved by the above approach but the m4a one is not responding to it!

I downloaded few sample m4a sample files and they uploaded correctly since the mime-types of those are all audio/x-m4a, and this is the value returned by get_real_type function.

Although adding a correct association should work ('m4a' => 'application/octet-stream') and the mime-type of your file is indeed application/octet-stream I am not sure why it is being rejected! However, none of the m4a files I downloaded is of application/octet-stream.

Can you send another m4a of application/octet-stream type file for further testing please?

@soleo
7 months ago

Another example for m4a audio file

#2 in reply to: ↑ 1 @soleo
7 months ago

Thanks for taking care of it.

I just attached another m4a file (xj.m4a). It was recorded using Vocienote app built in SAMSUNG S8.

Could you explain how you are going to fix it? The fix should work for the following types

  • an mp3 file could have a set of mime types such as audio/mpeg, video/mp4
  • similarly, an m4a file could have mime type audio/mpeg, audio/x-m4a or application/octet-stream

This is not a complete list of all variations of possible mime types, because every recording app handles it differently. Adding another set of mime type for mp3,m4a might solve this current bug, but it is very likely that there are other cases we may miss.

Is there a reason that we have to do mime type checking that strict?

Replying to subrataemfluence:

Welcome to trac and thanks for the report!

recording6021333337014136895.mp3 video/mp4
to_test_on_timby_voice_note.m4a application/octet-stream

The issue with the above files should ideally be fixed by adding right associations in wp_get_mime_types function inside wp_includes/functions.php file.

'mp3'   => 'video/mp4',
'm4a'   => 'application/octet-stream',

The issue with recording6021333337014136895.mp3 video/mp4 has actually resolved by the above approach but the m4a one is not responding to it!

I downloaded few sample m4a sample files and they uploaded correctly since the mime-types of those are all audio/x-m4a, and this is the value returned by get_real_type function.

Although adding a correct association should work ('m4a' => 'application/octet-stream') and the mime-type of your file is indeed application/octet-stream I am not sure why it is being rejected! However, none of the m4a files I downloaded is of application/octet-stream.

Can you send another m4a of application/octet-stream type file for further testing please?

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


7 months ago

Note: See TracTickets for help on using tickets.