Bug 1306755 - Copy rust mp4parse tests into the tree. r=kinetik,a=gchang
authorRalph Giles <giles@mozilla.com>
Fri, 30 Sep 2016 14:37:54 -0700
changeset 356492 e1a84f7fff9505dff8ac4315b9a7be611ab7d8ed
parent 356491 39384a565895fc84a42bc52febc59d11ab5b8fe5
child 356493 3d39e45e752d48c6f649e98cae0ea75ffbf2daf2
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, gchang
bugs1306755
milestone51.0a2
Bug 1306755 - Copy rust mp4parse tests into the tree. r=kinetik,a=gchang Having these files in-tree makes it possible to run `cargo test` to verify changes. MozReview-Commit-ID: 6x4XZaw4UtD
media/libstagefright/binding/mp4parse-cargo.patch
media/libstagefright/binding/mp4parse/tests/afl.rs
media/libstagefright/binding/mp4parse/tests/minimal.mp4
media/libstagefright/binding/mp4parse/tests/public.rs
media/libstagefright/binding/mp4parse_capi/Cargo.toml
media/libstagefright/binding/update-rust.sh
--- a/media/libstagefright/binding/mp4parse-cargo.patch
+++ b/media/libstagefright/binding/mp4parse-cargo.patch
@@ -1,27 +1,28 @@
 diff --git a/media/libstagefright/binding/mp4parse_capi/Cargo.toml b/media/libstagefright/binding/mp4parse_capi/Cargo.toml
 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",
  ]
  
 -build = "build.rs"
 -
  [dependencies]
  "mp4parse" = {version = "0.5.1", path = "../mp4parse"}
  
 -[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
 +++ b/media/libstagefright/binding/mp4parse/Cargo.toml
 @@ -18,17 +18,11 @@ exclude = [
  ]
  
  [dependencies]
new file mode 100644
--- /dev/null
+++ b/media/libstagefright/binding/mp4parse/tests/afl.rs
@@ -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);
+}
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9fe1e672241766bccf54731219bf03b81ff223ef
GIT binary patch
literal 2591
zc$|$Cdr%Z*{JT3))C`|NjOM4{3?&@9$8iw3gb@=?>Nq{LsitLbcaK|d_jcJ`;LbG9
z@I~)wOeRy2`Xe=^vP{!(u<|isW7<P4v{A%-4WLdbX<WbW06Bax{${`L`@O&4>sy2n
z_LxCUGE@a2D<UT>2UpJ1isqydis?{PwHzTNE9G7R^#R)%*z%ACk*^mleYI|;^HING
zgE$gRo$~?yqUnp=X}gWL)LSg?;$92c+9PC&D3}JEV?^07qbyQ;Z7uI8g2VxW72)RG
z9f;KH+3zDnx>u0(9!a?*h|!v}fL4n*zaWc5$MT3G`8|M)Dpw*-qr*%Qx@2PnUGzi+
zbx)Zt<8J(#VY+2Fs}0i-qI8y$rrn_wB=L4s1W3`HG;V>!a2R$PycSplG&FnyC6>Us
z@#vH({|+NPA)5_feC+*V3mV`(-`qH%ftVR)q^>=eSV)~nN)RsJmw#i80@>Uyk+rRt
z$E&^iu}vTw($8F2yU)DntSz@owf}kSXD(uT=A!b>bFm|Y(2&sW=E6|R{Lz|E11&_&
zg}r+&h8ap9r*|_Gm%3+S&P_A%JUn9Vmb9&;bzPwXxI{yUG|UzXg(iY92F`^1(Gi<C
zm8@9c#13CJs|5`J%tA_yquOlkS~1<X*ofcMsCHXX-*#K0c(}Lq5g;x70@jzX)}qKb
z-53L~iG2{ExJJO;WrE2?G8E08497>88(O4unkGk=JYDMQ>BRM>N}P@rxQKD2G}E|p
zPnOH>r0g_B-cg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Tf5gW^QSTERu5`!dH(Ek2a`8f
z#&18puc@$f^sbS|zHt>^57%s4kTL7PU)RHH+B?}s&yQDZ#oQUU{KAI8yDt_O%a=8I
zS5*$x3of<6lE3<^pA+^poPGDds+e)1UtWJJiLL$QWUzJTKlf{T)4f&gDetcMdW9!6
z{Z(cCOr~Q*%cbwC8&Uheoot%zyY}mO-`J`fTP`&K-Z5_{n-<@8_0+)pGh>l$t!dlP
zxqn>6_1cb|ar4{i<LlcCt}e)Kn}23tef!+wMFT58N@_@Is++y|L?GXCBJfhe;=_8#
V7H+%vO2y(I4x#uVR~Mjr{|DzpvIGDC
new file mode 100644
--- /dev/null
+++ b/media/libstagefright/binding/mp4parse/tests/public.rs
@@ -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 => {}
+        }
+    }
+}
--- a/media/libstagefright/binding/mp4parse_capi/Cargo.toml
+++ b/media/libstagefright/binding/mp4parse_capi/Cargo.toml
@@ -15,14 +15,11 @@ repository = "https://github.com/mozilla
 # Avoid complaints about trying to package test files.
 exclude = [
   "*.mp4",
 ]
 
 [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
--- a/media/libstagefright/binding/update-rust.sh
+++ b/media/libstagefright/binding/update-rust.sh
@@ -24,16 +24,19 @@ cargo build
 echo "Verifying sources..."
 cargo test
 popd
 popd
 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/
 cp _upstream/mp4parse/mp4parse_capi/build.rs mp4parse_capi/
 cp _upstream/mp4parse/mp4parse_capi/include/mp4parse.h include/
 cp _upstream/mp4parse/mp4parse_capi/src/*.rs mp4parse_capi/src/
 
 # TODO: download deps from crates.io.