Bug 1426773 - update rust mp4 parser. r?kinetik
MozReview-Commit-ID: 8GzXp7Oq9Wx
--- a/media/mp4parse-rust/mp4parse/src/lib.rs
+++ b/media/mp4parse-rust/mp4parse/src/lib.rs
@@ -1371,17 +1371,18 @@ fn read_flac_metadata<T: Read>(src: &mut
fn find_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
// Tags for elementary stream description
const ESDESCR_TAG: u8 = 0x03;
const DECODER_CONFIG_TAG: u8 = 0x04;
const DECODER_SPECIFIC_TAG: u8 = 0x05;
let mut remains = data;
- while !remains.is_empty() {
+ // Descriptor length should be more than 2 bytes.
+ while remains.len() > 2 {
let des = &mut Cursor::new(remains);
let tag = des.read_u8()?;
let mut end: u32 = 0; // It's u8 without declaration type that is incorrect.
// MSB of extend_or_len indicates more bytes, up to 4 bytes.
for _ in 0..4 {
let extend_or_len = des.read_u8()?;
end = (end << 7) + (extend_or_len & 0x7F) as u32;
--- a/media/mp4parse-rust/mp4parse/src/tests.rs
+++ b/media/mp4parse-rust/mp4parse/src/tests.rs
@@ -1102,16 +1102,38 @@ fn read_esds_invalid_descriptor() {
let mut stream = iter.next_box().unwrap().unwrap();
match super::read_esds(&mut stream) {
Err(Error::InvalidData(s)) => assert_eq!(s, "Invalid descriptor."),
_ => panic!("unexpected result with invalid descriptor"),
}
}
+#[test]
+fn read_esds_redundant_descriptor() {
+ // the '2' at the end is redundant data.
+ let esds =
+ vec![ 3, 25, 0, 1, 0, 4, 19, 64,
+ 21, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 119, 0, 5, 2, 18, 16,
+ 6, 1, 2,
+ ];
+
+ let mut stream = make_box(BoxSize::Auto, b"esds", |s| {
+ s.B32(0) // reserved
+ .append_bytes(esds.as_slice())
+ });
+ let mut iter = super::BoxIter::new(&mut stream);
+ let mut stream = iter.next_box().unwrap().unwrap();
+
+ match super::read_esds(&mut stream) {
+ Ok(esds) => assert_eq!(esds.audio_codec, super::CodecType::AAC),
+ _ => panic!("unexpected result with invalid descriptor"),
+ }
+}
#[test]
fn read_invalid_pssh() {
// invalid pssh header length
let pssh =
vec![
0x00, 0x00, 0x00, 0x01, 0x70,
0x73, 0x73, 0x68, 0x01, 0x00, 0x00, 0x00, 0x10,
--- 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=c714e7ee1218fb0f51d3c67166fd5fff303a0312
+VER=ec45de038401d060d826ed87d71e4c67b33a8db3
# Accept version or commit from the command line.
if test -n "$1"; then
VER=$1
fi
echo "Fetching sources..."
rm -rf _upstream