Bug 1457359 - Update mp4parse and disable FallibleVec when jemalloc is disabled. r=glandium,jya
☠☠ backed out by a7d70f62c805 ☠ ☠
authorMatthew Gregan <kinetik@flim.org>
Thu, 10 May 2018 12:11:51 +1200
changeset 417852 b5fac38dc791a9935f2d3713537f2e4350a1c2b7
parent 417851 77b189833de1067c21f8230d6c68a29f1e4d7455
child 417853 a7d70f62c8057a74ddcf7d80ed869c8e5b3f1075
push id103165
push userebalazs@mozilla.com
push dateFri, 11 May 2018 09:45:25 +0000
treeherdermozilla-inbound@59a49b12b268 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, jya
bugs1457359
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1457359 - Update mp4parse and disable FallibleVec when jemalloc is disabled. r=glandium,jya Update mp4parse-rust to 0c8e1d91464aaa63b82ebf076b63cda1df4230d1, which adds uuid parsing support and exports the mp4parse_fallible feature from mp4parse_capi. Update gkrust to pass MOZ_MEMORY as a feature, and use that to conditionally enable mp4parse_fallible/FallibleVec. MozReview-Commit-ID: 2HDYbL2CGgJ
media/mp4parse-rust/mp4parse-cargo.patch
media/mp4parse-rust/mp4parse/Cargo.toml
media/mp4parse-rust/mp4parse/src/boxes.rs
media/mp4parse-rust/mp4parse/src/lib.rs
media/mp4parse-rust/mp4parse/src/tests.rs
media/mp4parse-rust/mp4parse_capi/Cargo.toml
media/mp4parse-rust/update-rust.sh
toolkit/library/rust/Cargo.toml
toolkit/library/rust/gkrust-features.mozbuild
toolkit/library/rust/shared/Cargo.toml
--- a/media/mp4parse-rust/mp4parse-cargo.patch
+++ b/media/mp4parse-rust/mp4parse-cargo.patch
@@ -1,57 +1,23 @@
-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
-@@ -19,13 +19,9 @@
+diff --git a/media/mp4parse-rust/mp4parse_capi/Cargo.toml b/media/mp4parse-rust/mp4parse_capi/Cargo.toml
+index f04ad37ac568..a04b1e977735 100644
+--- a/media/mp4parse-rust/mp4parse_capi/Cargo.toml
++++ b/media/mp4parse-rust/mp4parse_capi/Cargo.toml
+@@ -18,6 +18,8 @@ exclude = [
    "*.mp4",
  ]
  
--[badges]
--travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
- 
- [dependencies]
- byteorder = "1.2.1"
--afl = { version = "0.3", optional = true }
--abort_on_panic = { version = "1.0.0", optional = true }
- bitreader = { version = "0.3.0" }
- num-traits = "0.2.0"
- mp4parse_fallible = { version = "0.0.1", optional = true }
-@@ -33,6 +29,3 @@
++build = false
++
+ [badges]
+ travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
  
- [dev-dependencies]
- test-assembler = "0.1.2"
--
--[features]
--fuzz = ["afl", "abort_on_panic"]
-
-diff --git a/media/libstagefright/binding/mp4parse_capi/Cargo.toml b/media/libstagefright/binding/mp4parse_capi/Cargo.toml
-index a30e045..a965f06 100644
---- a/media/libstagefright/binding/mp4parse_capi/Cargo.toml
-+++ b/media/libstagefright/binding/mp4parse_capi/Cargo.toml
-@@ -18,23 +18,16 @@
-   "*.mp4",
- ]
- 
--[badges]
--travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
-+build = false
- 
- [dependencies]
- byteorder = "1.2.1"
- log = "0.4"
- 
- # To enable fallible memory allocation, add 'features = ["mp4parse_fallible"]'
- # in mp4parse brace.
--mp4parse = {version = "0.10.1", path = "../mp4parse"}
-+mp4parse = {version = "0.10.1", path = "../mp4parse", features = ["mp4parse_fallible"]}
- num-traits = "0.2.0"
- 
+@@ -30,9 +32,6 @@ num-traits = "0.2.0"
  [dev-dependencies]
  env_logger = "0.5.3"
--
+ 
 -[build-dependencies]
 -cbindgen = "0.5.2"
 -
--[features]
--fuzz = ["mp4parse/fuzz"]
-
+ [features]
+ fuzz = ["mp4parse/fuzz"]
+ # Enable mp4parse_fallible to use fallible memory allocation rather than
--- a/media/mp4parse-rust/mp4parse/Cargo.toml
+++ b/media/mp4parse-rust/mp4parse/Cargo.toml
@@ -14,18 +14,25 @@ categories = ["multimedia::video"]
 
 repository = "https://github.com/mozilla/mp4parse-rust"
 
 # Avoid complaints about trying to package test files.
 exclude = [
   "*.mp4",
 ]
 
+[badges]
+travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
 
 [dependencies]
 byteorder = "1.2.1"
+afl = { version = "0.3", optional = true }
+abort_on_panic = { version = "1.0.0", optional = true }
 bitreader = { version = "0.3.0" }
 num-traits = "0.2.0"
 mp4parse_fallible = { version = "0.0.1", optional = true }
 log = "0.4"
 
 [dev-dependencies]
 test-assembler = "0.1.2"
+
+[features]
+fuzz = ["afl", "abort_on_panic"]
--- a/media/mp4parse-rust/mp4parse/src/boxes.rs
+++ b/media/mp4parse-rust/mp4parse/src/boxes.rs
@@ -134,9 +134,10 @@ box_database!(
     SchemeInformationBox              0x73636869, // "schi"
     TrackEncryptionBox                0x74656e63, // "tenc"
     ProtectionSchemeInformationBox    0x73696e66, // "sinf"
     OriginalFormatBox                 0x66726d61, // "frma"
     MP3AudioSampleEntry               0x2e6d7033, // ".mp3" - from F4V.
     CompositionOffsetBox              0x63747473, // "ctts"
     LPCMAudioSampleEntry              0x6C70636D, // "lpcm" - quicktime atom
     ALACSpecificBox                   0x616C6163, // "alac" - Also used by ALACSampleEntry
+    UuidBox                           0x75756964, // "uuid"
 );
--- a/media/mp4parse-rust/mp4parse/src/lib.rs
+++ b/media/mp4parse-rust/mp4parse/src/lib.rs
@@ -135,16 +135,18 @@ pub type Result<T> = std::result::Result
 #[derive(Debug, Clone, Copy)]
 struct BoxHeader {
     /// Box type.
     name: BoxType,
     /// Size of the box in bytes.
     size: u64,
     /// Offset to the start of the contained data (or header size).
     offset: u64,
+    /// Uuid for extended type.
+    uuid: Option<[u8; 16]>,
 }
 
 /// File type box 'ftyp'.
 #[derive(Debug)]
 struct FileTypeBox {
     major_brand: FourCC,
     minor_version: u32,
     compatible_brands: Vec<FourCC>,
@@ -588,25 +590,44 @@ fn read_box_header<T: ReadBytesExt>(src:
             if size64 < 16 {
                 return Err(Error::InvalidData("malformed wide size"));
             }
             size64
         }
         2...7 => return Err(Error::InvalidData("malformed size")),
         _ => size32 as u64,
     };
-    let offset = match size32 {
+    let mut offset = match size32 {
         1 => 4 + 4 + 8,
         _ => 4 + 4,
     };
+    let uuid = if name == BoxType::UuidBox {
+        if size >= offset + 16 {
+            let mut buffer = [0u8; 16];
+            let count = src.read(&mut buffer)?;
+            offset += count as u64;
+            if count == 16 {
+                Some(buffer)
+            } else {
+                debug!("malformed uuid (short read), skipping");
+                None
+            }
+        } else {
+            debug!("malformed uuid, skipping");
+            None
+        }
+    } else {
+        None
+    };
     assert!(offset <= size);
     Ok(BoxHeader {
         name: name,
         size: size,
         offset: offset,
+        uuid: uuid,
     })
 }
 
 /// Parse the extra header fields for a full box.
 fn read_fullbox_extra<T: ReadBytesExt>(src: &mut T) -> Result<(u8, u32)> {
     let version = src.read_u8()?;
     let flags_a = src.read_u8()?;
     let flags_b = src.read_u8()?;
--- a/media/mp4parse-rust/mp4parse/src/tests.rs
+++ b/media/mp4parse-rust/mp4parse/src/tests.rs
@@ -58,16 +58,27 @@ fn make_box<F>(size: BoxSize, name: &[u8
             box_size.set_const(section.size());
         }
         // Skip checking BoxSize::Unchecked* cases.
         _ => (),
     }
     Cursor::new(section.get_contents().unwrap())
 }
 
+fn make_uuid_box<F>(size: BoxSize, uuid: &[u8; 16], func: F) -> Cursor<Vec<u8>>
+    where F: Fn(Section) -> Section
+{
+    make_box(size, b"uuid", |mut s| {
+        for b in uuid {
+            s = s.B8(*b);
+        }
+        func(s)
+    })
+}
+
 fn make_fullbox<F>(size: BoxSize, name: &[u8; 4], version: u8, func: F) -> Cursor<Vec<u8>>
     where F: Fn(Section) -> Section
 {
     make_box(size, name, |s| {
         func(s.B8(version)
               .B8(0)
               .B8(0)
               .B8(0))
@@ -75,24 +86,26 @@ fn make_fullbox<F>(size: BoxSize, name: 
 }
 
 #[test]
 fn read_box_header_short() {
     let mut stream = make_box(BoxSize::Short(8), b"test", |s| s);
     let header = super::read_box_header(&mut stream).unwrap();
     assert_eq!(header.name, BoxType::UnknownBox(0x74657374)); // "test"
     assert_eq!(header.size, 8);
+    assert!(header.uuid.is_none());
 }
 
 #[test]
 fn read_box_header_long() {
     let mut stream = make_box(BoxSize::Long(16), b"test", |s| s);
     let header = super::read_box_header(&mut stream).unwrap();
     assert_eq!(header.name, BoxType::UnknownBox(0x74657374)); // "test"
     assert_eq!(header.size, 16);
+    assert!(header.uuid.is_none());
 }
 
 #[test]
 fn read_box_header_short_unknown_size() {
     let mut stream = make_box(BoxSize::Short(0), b"test", |s| s);
     match super::read_box_header(&mut stream) {
         Err(Error::Unsupported(s)) => assert_eq!(s, "unknown sized box"),
         _ => panic!("unexpected result reading box with unknown size"),
@@ -113,16 +126,51 @@ fn read_box_header_long_invalid_size() {
     let mut stream = make_box(BoxSize::UncheckedLong(2), b"test", |s| s);
     match super::read_box_header(&mut stream) {
         Err(Error::InvalidData(s)) => assert_eq!(s, "malformed wide size"),
         _ => panic!("unexpected result reading box with invalid size"),
     };
 }
 
 #[test]
+fn read_box_header_uuid() {
+    const HEADER_UUID: [u8; 16] = [
+        0x85, 0xc0, 0xb6,0x87,
+        0x82, 0x0f,
+        0x11, 0xe0,
+        0x81, 0x11,
+        0xf4, 0xce, 0x46, 0x2b, 0x6a, 0x48 ];
+
+    let mut stream = make_uuid_box(BoxSize::Short(24), &HEADER_UUID, |s| s);
+    let mut iter = super::BoxIter::new(&mut stream);
+    let stream = iter.next_box().unwrap().unwrap();
+    assert_eq!(stream.head.name, BoxType::UuidBox);
+    assert_eq!(stream.head.size, 24);
+    assert!(stream.head.uuid.is_some());
+    assert_eq!(stream.head.uuid.unwrap(), HEADER_UUID);
+}
+
+#[test]
+fn read_box_header_truncated_uuid() {
+    const HEADER_UUID: [u8; 16] = [
+        0x85, 0xc0, 0xb6,0x87,
+        0x82, 0x0f,
+        0x11, 0xe0,
+        0x81, 0x11,
+        0xf4, 0xce, 0x46, 0x2b, 0x6a, 0x48 ];
+
+    let mut stream = make_uuid_box(BoxSize::UncheckedShort(23), &HEADER_UUID, |s| s);
+    let mut iter = super::BoxIter::new(&mut stream);
+    let stream = iter.next_box().unwrap().unwrap();
+    assert_eq!(stream.head.name, BoxType::UuidBox);
+    assert_eq!(stream.head.size, 23);
+    assert!(stream.head.uuid.is_none());
+}
+
+#[test]
 fn read_ftyp() {
     let mut stream = make_box(BoxSize::Short(24), b"ftyp", |s| {
         s.append_bytes(b"mp42")
          .B32(0) // minor version
          .append_bytes(b"isom")
          .append_bytes(b"mp42")
     });
     let mut iter = super::BoxIter::new(&mut stream);
--- a/media/mp4parse-rust/mp4parse_capi/Cargo.toml
+++ b/media/mp4parse-rust/mp4parse_capi/Cargo.toml
@@ -15,19 +15,27 @@ repository = "https://github.com/mozilla
 
 # Avoid complaints about trying to package test files.
 exclude = [
   "*.mp4",
 ]
 
 build = false
 
+[badges]
+travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
+
 [dependencies]
 byteorder = "1.2.1"
 log = "0.4"
-
-# To enable fallible memory allocation, add 'features = ["mp4parse_fallible"]'
-# in mp4parse brace.
-mp4parse = {version = "0.10.1", path = "../mp4parse", features = ["mp4parse_fallible"]}
+mp4parse = {version = "0.10.1", path = "../mp4parse"}
 num-traits = "0.2.0"
 
 [dev-dependencies]
 env_logger = "0.5.3"
+
+[features]
+fuzz = ["mp4parse/fuzz"]
+# Enable mp4parse_fallible to use fallible memory allocation rather than
+# panicking on OOM.  Note that this is only safe within Gecko where the system
+# allocator has been globally overridden (see BMO 1457359).
+mp4parse_fallible = ["mp4parse/mp4parse_fallible"]
+
--- a/media/mp4parse-rust/update-rust.sh
+++ b/media/mp4parse-rust/update-rust.sh
@@ -1,13 +1,15 @@
-#!/bin/sh -e
+#!/bin/sh
 # Script to update mp4parse-rust sources to latest upstream
 
+set -e
+
 # Default version.
-VER="2dc5127a69bc9bf891972e269e3abde0b77612f5"
+VER="0c8e1d91464aaa63b82ebf076b63cda1df4230d1"
 
 # Accept version or commit from the command line.
 if test -n "$1"; then
   VER=$1
 fi
 
 echo "Fetching sources..."
 rm -rf _upstream
@@ -31,17 +33,17 @@ cp _upstream/mp4parse/mp4parse_capi/Carg
 cp _upstream/mp4parse/mp4parse_capi/build.rs mp4parse_capi/
 cp _upstream/mp4parse/mp4parse_capi/include/mp4parse.h ./
 cp _upstream/mp4parse/mp4parse_capi/src/*.rs mp4parse_capi/src/
 rm -rf mp4parse_fallible
 mkdir -p mp4parse_fallible
 cp _upstream/mp4parse_fallible/* mp4parse_fallible/
 
 echo "Applying patches..."
-patch -p4 < mp4parse-cargo.patch
+patch -p3 < mp4parse-cargo.patch
 
 echo "Cleaning up..."
 rm -rf _upstream
 
 echo "Updating gecko Cargo.lock..."
 pushd ../../toolkit/library/rust/
 cargo update --package mp4parse_capi
 popd
--- a/toolkit/library/rust/Cargo.toml
+++ b/toolkit/library/rust/Cargo.toml
@@ -10,16 +10,17 @@ bindgen = ["gkrust-shared/bindgen"]
 servo = ["gkrust-shared/servo"]
 quantum_render = ["gkrust-shared/quantum_render"]
 cubeb-remoting = ["gkrust-shared/cubeb-remoting"]
 cubeb_pulse_rust = ["gkrust-shared/cubeb_pulse_rust"]
 gecko_debug = ["gkrust-shared/gecko_debug"]
 simd-accel = ["gkrust-shared/simd-accel"]
 no-static-ideograph-encoder-tables = ["gkrust-shared/no-static-ideograph-encoder-tables"]
 oom_with_global_alloc = ["gkrust-shared/oom_with_global_alloc"]
+moz_memory = ["gkrust-shared/moz_memory"]
 
 [dependencies]
 gkrust-shared = { path = "shared" }
 
 [dev-dependencies]
 stylo_tests = { path = "../../../servo/ports/geckolib/tests/" }
 
 [lib]
--- a/toolkit/library/rust/gkrust-features.mozbuild
+++ b/toolkit/library/rust/gkrust-features.mozbuild
@@ -18,14 +18,17 @@ if CONFIG['MOZ_PULSEAUDIO']:
 if CONFIG['MOZ_RUST_SIMD']:
     gkrust_features += ['simd-accel']
 
 # This feature is only supported on Linux and macOS, and this check needs to
 # match MOZ_CUBEB_REMOTING in CubebUtils.cpp.
 if (CONFIG['OS_ARCH'] == 'Linux' and CONFIG['OS_TARGET'] != 'Android') or CONFIG['OS_ARCH'] == 'Darwin':
     gkrust_features += ['cubeb-remoting']
 
+if CONFIG['MOZ_MEMORY']:
+    gkrust_features += ['moz_memory']
+
 gkrust_features += ['no-static-ideograph-encoder-tables']
 
 # See details in toolkit/library/rust/shared/lib.rs
 # A string test is not the best thing, but it works well enough here.
 if CONFIG['RUSTC_VERSION'] < "1.27":
     gkrust_features += ['oom_with_global_alloc']
--- a/toolkit/library/rust/shared/Cargo.toml
+++ b/toolkit/library/rust/shared/Cargo.toml
@@ -34,16 +34,17 @@ bindgen = ["geckoservo/bindgen"]
 servo = ["geckoservo"]
 quantum_render = ["webrender_bindings"]
 cubeb-remoting = ["cubeb-sys", "audioipc-client", "audioipc-server"]
 cubeb_pulse_rust = ["cubeb-sys", "cubeb-pulse"]
 gecko_debug = ["geckoservo/gecko_debug", "nsstring/gecko_debug"]
 simd-accel = ["encoding_c/simd-accel", "encoding_glue/simd-accel"]
 no-static-ideograph-encoder-tables = ["encoding_c/no-static-ideograph-encoder-tables", "encoding_glue/no-static-ideograph-encoder-tables"]
 oom_with_global_alloc = []
+moz_memory = ["mp4parse_capi/mp4parse_fallible"]
 
 [lib]
 path = "lib.rs"
 test = false
 doctest = false
 bench = false
 doc = false
 plugin = false