Bug 1388618 - update mp4 rust parser to fix invalid PSSH box. r?kinetik
MozReview-Commit-ID: FnbgeNiKdR1
--- a/media/libstagefright/binding/mp4parse/src/lib.rs
+++ b/media/libstagefright/binding/mp4parse/src/lib.rs
@@ -704,36 +704,35 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>
_ => skip_box_content(&mut b)?,
};
check_parser_state!(b.content);
}
Ok(())
}
fn read_pssh<T: Read>(src: &mut BMFFBox<T>) -> Result<ProtectionSystemSpecificHeaderBox> {
- let mut box_content = Vec::with_capacity(src.head.size as usize);
- src.read_to_end(&mut box_content)?;
-
+ let len = src.bytes_left();
+ let mut box_content = read_buf(src, len)?;
let (system_id, kid, data) = {
let pssh = &mut Cursor::new(box_content.as_slice());
let (version, _) = read_fullbox_extra(pssh)?;
let system_id = read_buf(pssh, 16)?;
let mut kid: Vec<ByteData> = Vec::new();
if version > 0 {
- let count = be_i32(pssh)?;
+ let count = be_u32_with_limit(pssh)?;
for _ in 0..count {
let item = read_buf(pssh, 16)?;
kid.push(item);
}
}
- let data_size = be_i32(pssh)? as usize;
+ let data_size = be_u32_with_limit(pssh)? as usize;
let data = read_buf(pssh, data_size)?;
(system_id, kid, data)
};
let mut pssh_box = Vec::new();
write_be_u32(&mut pssh_box, src.head.size as u32)?;
pssh_box.append(&mut b"pssh".to_vec());
--- a/media/libstagefright/binding/mp4parse/src/tests.rs
+++ b/media/libstagefright/binding/mp4parse/src/tests.rs
@@ -1098,8 +1098,33 @@ 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_invalid_pssh() {
+ // invalid pssh header length
+ let pssh =
+ vec![
+ 0x00, 0x00, 0x00, 0x01, 0x70,
+ 0x73, 0x73, 0x68, 0x01, 0x00, 0x00, 0x00, 0x10,
+ 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, 0xac,
+ 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b, 0x00,
+ 0x00, 0x00, 0x02, 0x7e, 0x57, 0x1d, 0x01, 0x7e,
+ ];
+
+ let mut stream = make_box(BoxSize::Auto, b"moov", |s| {
+ s.append_bytes(pssh.as_slice())
+ });
+ let mut iter = super::BoxIter::new(&mut stream);
+ let mut stream = iter.next_box().unwrap().unwrap();
+ let mut context = super::MediaContext::new();
+
+ match super::read_moov(&mut stream, &mut context) {
+ Err(Error::InvalidData(s)) => assert_eq!(s, "read_buf size exceeds BUF_SIZE_LIMIT"),
+ _ => panic!("unexpected result with invalid descriptor"),
+ }
+}
--- a/media/libstagefright/binding/update-rust.sh
+++ b/media/libstagefright/binding/update-rust.sh
@@ -1,13 +1,13 @@
#!/bin/sh -e
# Script to update mp4parse-rust sources to latest upstream
# Default version.
-VER=f63b23d75ffa823d713a2a10724acd9cd6689ebc
+VER=81260ded506dce968716720e10544c510f37d222
# Accept version or commit from the command line.
if test -n "$1"; then
VER=$1
fi
echo "Fetching sources..."
rm -rf _upstream