Bug 1389470 - reduce table size on 32bit arch to avoid OOM. r?kinetik
MozReview-Commit-ID: C0O7Gnxbocy
--- a/media/libstagefright/binding/mp4parse/src/lib.rs
+++ b/media/libstagefright/binding/mp4parse/src/lib.rs
@@ -25,18 +25,23 @@ use boxes::{BoxType, FourCC};
#[cfg(test)]
mod tests;
// Arbitrary buffer size limit used for raw read_bufs on a box.
const BUF_SIZE_LIMIT: usize = 1024 * 1024;
// Max table length. Calculating in worth case for one week long video, one
// frame per table entry in 30 fps.
+#[cfg(target_pointer_width = "64")]
const TABLE_SIZE_LIMIT: u32 = 30 * 60 * 60 * 24 * 7;
+// Reduce max table length if it is in 32 arch for memory problem.
+#[cfg(target_pointer_width = "32")]
+const TABLE_SIZE_LIMIT: u32 = 30 * 60 * 60 * 24;
+
static DEBUG_MODE: std::sync::atomic::AtomicBool = std::sync::atomic::ATOMIC_BOOL_INIT;
pub fn set_debug_mode(mode: bool) {
DEBUG_MODE.store(mode, std::sync::atomic::Ordering::SeqCst);
}
#[inline(always)]
fn get_debug_mode() -> bool {
@@ -1328,23 +1333,22 @@ fn find_descriptor(data: &[u8], esds: &m
let mut remains = data;
while !remains.is_empty() {
let des = &mut Cursor::new(remains);
let tag = des.read_u8()?;
let mut end = 0;
- // Extension descriptor could be variable size from 0x80 to
- // 0x80 0x80 0x80, the descriptor length is the byte after that,
- // so it loops four times.
+ // MSB of extend_or_len indicates more bytes, up to 4 bytes.
for _ in 0..4 {
let extend_or_len = des.read_u8()?;
- if extend_or_len < 0x80 {
- end = extend_or_len + des.position() as u8;
+ end = (end << 7) + (extend_or_len & 0x7F);
+ if (extend_or_len & 0x80) == 0 {
+ end += des.position() as u8;
break;
}
};
if end as usize > remains.len() {
return Err(Error::InvalidData("Invalid descriptor."));
}
--- a/media/libstagefright/binding/mp4parse/src/tests.rs
+++ b/media/libstagefright/binding/mp4parse/src/tests.rs
@@ -970,16 +970,33 @@ fn read_esds_one_byte_extension_descript
assert_eq!(es.audio_codec, super::CodecType::AAC);
assert_eq!(es.audio_object_type, Some(2));
assert_eq!(es.audio_sample_rate, Some(48000));
assert_eq!(es.audio_channel_count, Some(2));
}
#[test]
+fn read_esds_byte_extension_descriptor() {
+ let mut stream = make_box(BoxSize::Auto, b"esds", |s| {
+ s.B32(0) // reserved
+ .B16(0x0003)
+ .B16(0x8181) // extension byte length 0x81
+ .append_repeated(0, 0x81)
+ });
+ let mut iter = super::BoxIter::new(&mut stream);
+ let mut stream = iter.next_box().unwrap().unwrap();
+
+ match super::read_esds(&mut stream) {
+ Ok(_) => (),
+ _ => panic!("fail to parse descriptor extension byte length"),
+ }
+}
+
+#[test]
fn read_f4v_stsd() {
let mut stream = make_box(BoxSize::Auto, b".mp3", |s| {
s.append_repeated(0, 6)
.B16(1)
.B16(0)
.append_repeated(0, 6)
.B16(2)
.B16(16)
--- 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=7563263b6804a81986cc93b557fe05bd57fd57b3
+VER=1d2d69df3380139ee208f58181c73b1947c91ac2
# Accept version or commit from the command line.
if test -n "$1"; then
VER=$1
fi
echo "Fetching sources..."
rm -rf _upstream