Skip to content

Commit 4f70fc9

Browse files
Zaggy1024kinetiknz
authored andcommitted
Check for unknown sized boxes by the u32 size, but not the wide size.
Checking unknown sized boxes the total size allows wide boxes' size to be 0, causing panics to happen later when the box content offset is greater than the total box size.
1 parent f908f80 commit 4f70fc9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

mp4parse/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,12 +2373,11 @@ fn read_box_header<T: ReadBytesExt>(src: &mut T) -> Result<Option<BoxHeader>> {
23732373
} else {
23742374
None
23752375
};
2376-
if size != 0 && offset > size {
2377-
if size32 == 1 {
2378-
return Err(Error::from(Status::BoxBadWideSize));
2379-
} else {
2380-
return Err(Error::from(Status::BoxBadSize));
2381-
}
2376+
match size32 {
2377+
0 => (),
2378+
1 if offset > size => return Err(Error::from(Status::BoxBadWideSize)),
2379+
_ if offset > size => return Err(Error::from(Status::BoxBadSize)),
2380+
_ => (),
23822381
}
23832382
Ok(Some(BoxHeader {
23842383
name,

mp4parse/tests/public.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static IMAGE_AVIF_UNKNOWN_MDAT_SIZE_IN_OVERSIZED_META: &str =
7171
static IMAGE_AVIF_VALID_WITH_GARBAGE_OVERREAD_AT_END: &str =
7272
"tests/valid_with_garbage_overread.avif";
7373
static IMAGE_AVIF_VALID_WITH_GARBAGE_BYTE_AT_END: &str = "tests/valid_with_garbage_byte.avif";
74+
static IMAGE_AVIF_WIDE_BOX_SIZE_0: &str = "tests/wide_box_size_0.avif";
7475
static AVIF_TEST_DIRS: &[&str] = &["tests", "av1-avif/testFiles", "link-u-avif-sample-images"];
7576

7677
// These files are
@@ -130,6 +131,7 @@ static AVIF_UNSUPPORTED_IMAGES: &[&str] = &[
130131
// TODO: make this into a map of expected errors?
131132
static AV1_AVIF_CORRUPT_IMAGES: &[&str] = &[
132133
IMAGE_AVIF_UNKNOWN_MDAT_SIZE_IN_OVERSIZED_META,
134+
IMAGE_AVIF_WIDE_BOX_SIZE_0,
133135
"av1-avif/testFiles/Link-U/kimono.crop.avif",
134136
"av1-avif/testFiles/Link-U/kimono.mirror-horizontal.avif",
135137
"av1-avif/testFiles/Link-U/kimono.mirror-vertical.avif",
@@ -1295,6 +1297,15 @@ fn public_avif_valid_with_garbage_byte_at_end() {
12951297
assert_avif_should(IMAGE_AVIF_VALID_WITH_GARBAGE_BYTE_AT_END, Status::Eof);
12961298
}
12971299

1300+
#[test]
1301+
fn public_avif_bad_video_sample_entry() {
1302+
let input = &mut File::open(IMAGE_AVIF_WIDE_BOX_SIZE_0).expect("Unknown file");
1303+
assert_eq!(
1304+
Status::from(mp4::read_avif(input, ParseStrictness::Normal)),
1305+
Status::BoxBadWideSize
1306+
);
1307+
}
1308+
12981309
fn public_avis_loop_impl(path: &str, looped: bool) {
12991310
let input = &mut File::open(path).expect("Unknown file");
13001311
match mp4::read_avif(input, ParseStrictness::Normal) {

mp4parse/tests/wide_box_size_0.avif

345 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)