Fixed mp4 ftyp matches should be case insensitive

Sim

Well-known member
Affected version
XF2.1.4 + XFMG 2.1.4
I've just set up a new XF installation with XFMG and have been trying to upload videos to the gallery.

These files are in mp4 format but every file I've tried to upload has given me an error The uploaded file was not a video as expected.

After quite a long time tracing through the code to work out why these mp4 files are failing, I determined that there is a bug in the video type detection function.

In XF\Http\Upload::analyzeVideo(), you are comparing the first few bytes of the file to a pre-determined set of file types:

PHP:
        $mp4Ftypes = [
            'avc1', 'iso2', 'iso6', 'isom', 'mmp4', 'msnv',
            'ndas', 'ndsc', 'ndsh', 'ndsm', 'ndsp', 'ndss', 'ndxc', 'ndxh',
            'ndxm', 'ndxp', 'ndxs', 'XAVC'
            // mp41/2 handled via regex
        ];

Looking at my mp4 files, they all contain ftypMSNV, with the MSNV in upper case.

However, you are doing a case sensitive preg_match against msnv in lower case, which means that it is not finding a match in my files.

Can I suggest you either add the upper case MSNV to the list of $mp4Ftypes or alternatively, make the match case insensitive, for example:

PHP:
// add i modifier to make search case insensitive
if (preg_match('#^(....)ftyp(M4V |qt  |mp4[0-9]|' . $mp4FtypesRegex . ')#i', $preamble, $match))
{
    ...
}

I've tested both these approaches, and they both work fine with my video files.

I also note that most references I find to MSNV online has it listed in upper case, so it seems that this is the expected format.
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.5).

Change log:
Switch to a case insensitive match when analyzing an MP4 video ftyp types.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Back
Top Bottom