Bug 1455701 - Update mp4parse-rust to upstream. r=padenot
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 26 Apr 2018 10:18:03 +0200
changeset 460820 dbf976eaf769cae4d8a87b4f6e26d7a6caa20d92
parent 460819 902a66d98a6a3894bece6525370f220d2de749c2
child 460821 6f5749b48d10d89251eeea5aba0c188cb594b8a2
push id165
push userfmarier@mozilla.com
push dateMon, 30 Apr 2018 23:50:51 +0000
reviewerspadenot
bugs1455701
milestone61.0a1
Bug 1455701 - Update mp4parse-rust to upstream. r=padenot MozReview-Commit-ID: AJXc5W4Rt0t
media/mp4parse-rust/mp4parse/src/lib.rs
media/mp4parse-rust/mp4parse/src/tests.rs
media/mp4parse-rust/update-rust.sh
--- a/media/mp4parse-rust/mp4parse/src/lib.rs
+++ b/media/mp4parse-rust/mp4parse/src/lib.rs
@@ -830,34 +830,40 @@ fn read_trak<T: Read>(f: &mut BMFFBox<T>
 }
 
 fn read_edts<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
     let mut iter = f.box_iter();
     while let Some(mut b) = iter.next_box()? {
         match b.head.name {
             BoxType::EditListBox => {
                 let elst = read_elst(&mut b)?;
+                if elst.edits.len() < 1 {
+                    debug!("empty edit list");
+                    continue;
+                }
                 let mut empty_duration = 0;
                 let mut idx = 0;
-                if elst.edits.len() > 2 {
-                    return Err(Error::Unsupported("more than two edits"));
-                }
                 if elst.edits[idx].media_time == -1 {
+                    if elst.edits.len() < 2 {
+                        debug!("expected additional edit, ignoring edit list");
+                        continue;
+                    }
                     empty_duration = elst.edits[idx].segment_duration;
-                    if elst.edits.len() < 2 {
-                        return Err(Error::InvalidData("expected additional edit"));
-                    }
                     idx += 1;
                 }
                 track.empty_duration = Some(MediaScaledTime(empty_duration));
-                if elst.edits[idx].media_time < 0 {
-                    return Err(Error::InvalidData("unexpected negative media time in edit"));
+                let media_time = elst.edits[idx].media_time;
+                if media_time < 0 {
+                    debug!("unexpected negative media time in edit");
                 }
-                track.media_time = Some(TrackScaledTime::<u64>(elst.edits[idx].media_time as u64,
+                track.media_time = Some(TrackScaledTime::<u64>(std::cmp::max(0, media_time) as u64,
                                                         track.id));
+                if elst.edits.len() > 2 {
+                    debug!("ignoring edit list with {} entries", elst.edits.len());
+                }
                 debug!("{:?}", elst);
             }
             _ => skip_box_content(&mut b)?,
         };
         check_parser_state!(b.content);
     }
     Ok(())
 }
@@ -1063,19 +1069,16 @@ fn read_tkhd<T: Read>(src: &mut BMFFBox<
         matrix: matrix,
     })
 }
 
 /// Parse a elst box.
 fn read_elst<T: Read>(src: &mut BMFFBox<T>) -> Result<EditListBox> {
     let (version, _) = read_fullbox_extra(src)?;
     let edit_count = be_u32_with_limit(src)?;
-    if edit_count == 0 {
-        return Err(Error::InvalidData("invalid edit count"));
-    }
     let mut edits = Vec::new();
     for _ in 0..edit_count {
         let (segment_duration, media_time) = match version {
             1 => {
                 // 64 bit segment duration and media times.
                 (be_u64(src)?, be_i64(src)?)
             }
             0 => {
@@ -1089,16 +1092,19 @@ fn read_elst<T: Read>(src: &mut BMFFBox<
         vec_push(&mut edits, Edit {
             segment_duration: segment_duration,
             media_time: media_time,
             media_rate_integer: media_rate_integer,
             media_rate_fraction: media_rate_fraction,
         })?;
     }
 
+    // Padding could be added in some contents.
+    skip_box_remain(src)?;
+
     Ok(EditListBox {
         edits: edits,
     })
 }
 
 /// Parse a mdhd box.
 fn read_mdhd<T: Read>(src: &mut BMFFBox<T>) -> Result<MediaHeaderBox> {
     let (version, _) = read_fullbox_extra(src)?;
--- a/media/mp4parse-rust/mp4parse/src/tests.rs
+++ b/media/mp4parse-rust/mp4parse/src/tests.rs
@@ -754,19 +754,18 @@ fn read_elst_zero_entries() {
     let mut stream = make_fullbox(BoxSize::Auto, b"elst", 0, |s| {
         s.B32(0)
          .B16(12)
          .B16(34)
     });
     let mut iter = super::BoxIter::new(&mut stream);
     let mut stream = iter.next_box().unwrap().unwrap();
     match super::read_elst(&mut stream) {
-        Err(Error::InvalidData(s)) => assert_eq!(s, "invalid edit count"),
-        Ok(_) => panic!("expected an error result"),
-        _ => panic!("expected a different error result"),
+        Ok(elst) => assert_eq!(elst.edits.len(), 0),
+        _ => panic!("expected no error"),
     }
 }
 
 fn make_elst() -> Cursor<Vec<u8>> {
     make_fullbox(BoxSize::Auto, b"elst", 1, |s| {
         s.B32(1)
         // first entry
          .B64(1234) // duration
@@ -775,26 +774,29 @@ fn make_elst() -> Cursor<Vec<u8>> {
          .B16(34) // rate fraction
     })
 }
 
 #[test]
 fn read_edts_bogus() {
     // First edit list entry has a media_time of -1, so we expect a second
     // edit list entry to be present to provide a valid media_time.
+    // Bogus edts are ignored.
     let mut stream = make_box(BoxSize::Auto, b"edts", |s| {
         s.append_bytes(&make_elst().into_inner())
     });
     let mut iter = super::BoxIter::new(&mut stream);
     let mut stream = iter.next_box().unwrap().unwrap();
     let mut track = super::Track::new(0);
     match super::read_edts(&mut stream, &mut track) {
-        Err(Error::InvalidData(s)) => assert_eq!(s, "expected additional edit"),
-        Ok(_) => panic!("expected an error result"),
-        _ => panic!("expected a different error result"),
+        Ok(_) => {
+            assert_eq!(track.media_time, None);
+            assert_eq!(track.empty_duration, None);
+        }
+        _ => panic!("expected no error"),
     }
 }
 
 #[test]
 fn skip_padding_in_boxes() {
     // Padding data could be added in the end of these boxes. Parser needs to skip
     // them instead of returning error.
     let box_names = vec![b"stts", b"stsc", b"stsz", b"stco", b"co64", b"stss"];
--- a/media/mp4parse-rust/update-rust.sh
+++ b/media/mp4parse-rust/update-rust.sh
@@ -1,13 +1,13 @@
 #!/bin/sh -e
 # Script to update mp4parse-rust sources to latest upstream
 
 # Default version.
-VER="9e70cb418401c152cd3183aab06b084c0ce3f3e6"
+VER="2dc5127a69bc9bf891972e269e3abde0b77612f5"
 
 # Accept version or commit from the command line.
 if test -n "$1"; then
   VER=$1
 fi
 
 echo "Fetching sources..."
 rm -rf _upstream