зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1306755 - Copy rust mp4parse tests into the tree. r=kinetik
Having these files in-tree makes it possible to run `cargo test` to verify changes. MozReview-Commit-ID: 6x4XZaw4UtD --HG-- extra : rebase_source : 293572cbbc21929b43a735bf53ddb5521503bcd2
This commit is contained in:
Родитель
acb6be9f73
Коммит
17ec242a0b
|
@ -2,7 +2,7 @@ diff --git a/media/libstagefright/binding/mp4parse_capi/Cargo.toml b/media/libst
|
|||
index 5092cd7..ecbc8c0 100644
|
||||
--- a/media/libstagefright/binding/mp4parse_capi/Cargo.toml
|
||||
+++ b/media/libstagefright/binding/mp4parse_capi/Cargo.toml
|
||||
@@ -17,14 +17,9 @@ exclude = [
|
||||
@@ -17,15 +17,7 @@ exclude = [
|
||||
"*.mp4",
|
||||
]
|
||||
|
||||
|
@ -14,9 +14,10 @@ index 5092cd7..ecbc8c0 100644
|
|||
-[build-dependencies]
|
||||
-rusty-cheddar = "0.3.2"
|
||||
-
|
||||
[features]
|
||||
fuzz = ["mp4parse/fuzz"]
|
||||
|
||||
-[features]
|
||||
-fuzz = ["mp4parse/fuzz"]
|
||||
-
|
||||
# Somewhat heavy-handed, but we want at least -Z force-overflow-checks=on.
|
||||
diff --git a/media/libstagefright/binding/mp4parse/Cargo.toml b/media/libstagefright/binding/mp4parse/Cargo.toml
|
||||
index ff9422c..814c4c6 100644
|
||||
--- a/media/libstagefright/binding/mp4parse/Cargo.toml
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/// Regression tests from American Fuzzy Lop test cases.
|
||||
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
/// These all caused panics at some point during development.
|
||||
|
||||
extern crate mp4parse;
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
/// https://github.com/mozilla/mp4parse-rust/issues/2
|
||||
///
|
||||
/// Test a box with 4-byte size, smaller than the smallest header.
|
||||
#[test]
|
||||
fn fuzz_2() {
|
||||
let mut c = Cursor::new(b"\x00\x00\x00\x04\xa6\x00\x04\xa6".to_vec());
|
||||
let mut context = mp4parse::MediaContext::new();
|
||||
let _ = mp4parse::read_mp4(&mut c, &mut context);
|
||||
}
|
||||
|
||||
/// https://github.com/mozilla/mp4parse-rust/issues/4
|
||||
///
|
||||
/// Test a large (64 bit) box header with zero declared size.
|
||||
#[test]
|
||||
fn fuzz_4() {
|
||||
let mut c = Cursor::new(b"\x00\x00\x00\x01\x30\x30\x30\x30\x00\x00\x00\x00\x00\x00\x00\x00".to_vec());
|
||||
let mut context = mp4parse::MediaContext::new();
|
||||
let _ = mp4parse::read_mp4(&mut c, &mut context);
|
||||
}
|
||||
|
||||
/// https://github.com/mozilla/mp4parse-rust/issues/5
|
||||
///
|
||||
/// Declares 202116104 compatible brands but does not supply them,
|
||||
/// verifying read is properly bounded at the end of the stream.
|
||||
#[test]
|
||||
fn fuzz_5() {
|
||||
let mut c = Cursor::new(b"\x30\x30\x30\x30\x66\x74\x79\x70\x30\x30\x30\x30\x30\x30\x30\x30".to_vec());
|
||||
let mut context = mp4parse::MediaContext::new();
|
||||
let _ = mp4parse::read_mp4(&mut c, &mut context);
|
||||
}
|
||||
|
||||
/// https://github.com/mozilla/mp4parse-rust/issues/6
|
||||
///
|
||||
/// Declares an ftyp box with a single invalid (short - 3 byte) compatible
|
||||
/// brand and excludes the extra 3 bytes from the stream.
|
||||
#[test]
|
||||
fn fuzz_6() {
|
||||
let mut c = Cursor::new(b"\x00\x00\x00\x13\x66\x74\x79\x70\x30\x30\x30\x30\x30\x30\x30\x30".to_vec());
|
||||
let mut context = mp4parse::MediaContext::new();
|
||||
let _ = mp4parse::read_mp4(&mut c, &mut context);
|
||||
}
|
Двоичный файл не отображается.
|
@ -0,0 +1,89 @@
|
|||
/// Check if needed fields are still public.
|
||||
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
extern crate mp4parse as mp4;
|
||||
|
||||
use std::io::{Cursor, Read};
|
||||
use std::fs::File;
|
||||
|
||||
// Taken from https://github.com/GuillaumeGomez/audio-video-metadata/blob/9dff40f565af71d5502e03a2e78ae63df95cfd40/src/metadata.rs#L53
|
||||
#[test]
|
||||
fn public_api() {
|
||||
let mut fd = File::open("tests/minimal.mp4").expect("Unknown file");
|
||||
let mut buf = Vec::new();
|
||||
fd.read_to_end(&mut buf).expect("File error");
|
||||
|
||||
let mut c = Cursor::new(&buf);
|
||||
let mut context = mp4::MediaContext::new();
|
||||
mp4::read_mp4(&mut c, &mut context).expect("read_mp4 failed");
|
||||
assert_eq!(context.timescale, Some(mp4::MediaTimeScale(1000)));
|
||||
for track in context.tracks {
|
||||
match track.data {
|
||||
Some(mp4::SampleEntry::Video(v)) => {
|
||||
// track part
|
||||
assert_eq!(track.duration, Some(mp4::TrackScaledTime(512, 0)));
|
||||
assert_eq!(track.empty_duration, Some(mp4::MediaScaledTime(0)));
|
||||
assert_eq!(track.media_time, Some(mp4::TrackScaledTime(0, 0)));
|
||||
assert_eq!(track.timescale, Some(mp4::TrackTimeScale(12800, 0)));
|
||||
assert_eq!(v.width, 320);
|
||||
assert_eq!(v.height, 240);
|
||||
|
||||
// track.tkhd part
|
||||
let tkhd = track.tkhd.unwrap();
|
||||
assert_eq!(tkhd.disabled, false);
|
||||
assert_eq!(tkhd.duration, 40);
|
||||
assert_eq!(tkhd.width, 20971520);
|
||||
assert_eq!(tkhd.height, 15728640);
|
||||
|
||||
// track.data part
|
||||
assert_eq!(match v.codec_specific {
|
||||
mp4::VideoCodecSpecific::AVCConfig(v) => {
|
||||
assert!(v.len() > 0);
|
||||
"AVC"
|
||||
}
|
||||
mp4::VideoCodecSpecific::VPxConfig(vpx) => {
|
||||
// We don't enter in here, we just check if fields are public.
|
||||
assert!(vpx.bit_depth > 0);
|
||||
assert!(vpx.color_space > 0);
|
||||
assert!(vpx.chroma_subsampling > 0);
|
||||
assert!(vpx.codec_init.len() > 0);
|
||||
"VPx"
|
||||
}
|
||||
}, "AVC");
|
||||
}
|
||||
Some(mp4::SampleEntry::Audio(a)) => {
|
||||
// track part
|
||||
assert_eq!(track.duration, Some(mp4::TrackScaledTime(2944, 1)));
|
||||
assert_eq!(track.empty_duration, Some(mp4::MediaScaledTime(0)));
|
||||
assert_eq!(track.media_time, Some(mp4::TrackScaledTime(1024, 1)));
|
||||
assert_eq!(track.timescale, Some(mp4::TrackTimeScale(48000, 1)));
|
||||
|
||||
// track.tkhd part
|
||||
let tkhd = track.tkhd.unwrap();
|
||||
assert_eq!(tkhd.disabled, false);
|
||||
assert_eq!(tkhd.duration, 62);
|
||||
assert_eq!(tkhd.width, 0);
|
||||
assert_eq!(tkhd.height, 0);
|
||||
|
||||
// track.data part
|
||||
assert_eq!(match a.codec_specific {
|
||||
mp4::AudioCodecSpecific::ES_Descriptor(v) => {
|
||||
assert!(v.len() > 0);
|
||||
"ES"
|
||||
}
|
||||
mp4::AudioCodecSpecific::OpusSpecificBox(opus) => {
|
||||
// We don't enter in here, we just check if fields are public.
|
||||
assert!(opus.version > 0);
|
||||
"Opus"
|
||||
}
|
||||
}, "ES");
|
||||
assert!(a.samplesize > 0);
|
||||
assert!(a.samplerate > 0);
|
||||
}
|
||||
Some(mp4::SampleEntry::Unknown) | None => {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,9 +20,6 @@ exclude = [
|
|||
[dependencies]
|
||||
"mp4parse" = {version = "0.5.1", path = "../mp4parse"}
|
||||
|
||||
[features]
|
||||
fuzz = ["mp4parse/fuzz"]
|
||||
|
||||
# Somewhat heavy-handed, but we want at least -Z force-overflow-checks=on.
|
||||
[profile.release]
|
||||
debug-assertions = true
|
||||
|
|
|
@ -29,6 +29,9 @@ rm -rf mp4parse
|
|||
mkdir -p mp4parse/src
|
||||
cp _upstream/mp4parse/mp4parse/Cargo.toml mp4parse/
|
||||
cp _upstream/mp4parse/mp4parse/src/*.rs mp4parse/src/
|
||||
mkdir -p mp4parse/tests
|
||||
cp _upstream/mp4parse/mp4parse/tests/*.rs mp4parse/tests/
|
||||
cp _upstream/mp4parse/mp4parse/tests/*.mp4 mp4parse/tests/
|
||||
rm -rf mp4parse_capi
|
||||
mkdir -p mp4parse_capi/src
|
||||
cp _upstream/mp4parse/mp4parse_capi/Cargo.toml mp4parse_capi/
|
||||
|
|
Загрузка…
Ссылка в новой задаче