mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1079747 - Follow WhatWG's MIMESniff spec for MP4 more closely. r=cpearce
This commit is contained in:
parent
ed7832a2e4
commit
32e282c7c8
@ -38,6 +38,26 @@ nsMediaSniffer::nsMediaSnifferEntry nsMediaSniffer::sSnifferEntries[] = {
|
||||
PATTERN_ENTRY("\xFF\xFF\xFF", "ID3", AUDIO_MP3)
|
||||
};
|
||||
|
||||
static bool MatchesMP4orISOBrand(const uint8_t aData[4])
|
||||
{
|
||||
// Return true if aData contains the string "mp4" (last byte ignored).
|
||||
if (aData[0] == 0x6D &&
|
||||
aData[1] == 0x70 &&
|
||||
aData[2] == 0x34) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return true if aData contains the string "isom", or "iso2".
|
||||
if (aData[0] == 0x69 &&
|
||||
aData[1] == 0x73 &&
|
||||
aData[2] == 0x6F &&
|
||||
(aData[3] == 0x6D || aData[3] == 0x32)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// This function implements mp4 sniffing algorithm, described at
|
||||
// http://mimesniff.spec.whatwg.org/#signature-for-mp4
|
||||
static bool MatchesMP4(const uint8_t* aData, const uint32_t aLength)
|
||||
@ -59,24 +79,18 @@ static bool MatchesMP4(const uint8_t* aData, const uint32_t aLength)
|
||||
aData[7] != 0x70) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 2; i <= boxSize / 4 - 1 ; i++) {
|
||||
if (i == 3) {
|
||||
continue;
|
||||
}
|
||||
// The string "mp42" or "mp41".
|
||||
if (aData[4*i] == 0x6D &&
|
||||
aData[4*i+1] == 0x70 &&
|
||||
aData[4*i+2] == 0x34) {
|
||||
return true;
|
||||
}
|
||||
// The string "isom" or "iso2".
|
||||
if (aData[4*i] == 0x69 &&
|
||||
aData[4*i+1] == 0x73 &&
|
||||
aData[4*i+2] == 0x6F &&
|
||||
(aData[4*i+3] == 0x6D || aData[4*i+3] == 0x32)) {
|
||||
return true;
|
||||
}
|
||||
if (MatchesMP4orISOBrand(&aData[8])) {
|
||||
return true;
|
||||
}
|
||||
// Skip minor_version (bytes 12-15).
|
||||
uint32_t bytesRead = 16;
|
||||
while (bytesRead < boxSize) {
|
||||
if (MatchesMP4orISOBrand(&aData[bytesRead])) {
|
||||
return true;
|
||||
}
|
||||
bytesRead += 4;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
BIN
toolkit/components/mediasniffer/test/unit/data/bug1079747.mp4
Normal file
BIN
toolkit/components/mediasniffer/test/unit/data/bug1079747.mp4
Normal file
Binary file not shown.
@ -39,6 +39,8 @@ const tests = [
|
||||
{ path: "data/fl10.mp2", expected: "application/octet-stream" },
|
||||
// Truncated ff installer regression test for bug 875769.
|
||||
{ path: "data/ff-inst.exe", expected: "application/octet-stream" },
|
||||
// MP4 with invalid box size (0) for "ftyp".
|
||||
{ path: "data/bug1079747.mp4", expected: "application/octet-stream" },
|
||||
];
|
||||
|
||||
// A basic listener that reads checks the if we sniffed properly.
|
||||
|
@ -3,6 +3,7 @@ head =
|
||||
tail =
|
||||
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
support-files =
|
||||
data/bug1079747.mp4
|
||||
data/detodos.mp3
|
||||
data/ff-inst.exe
|
||||
data/file.mkv
|
||||
|
Loading…
Reference in New Issue
Block a user