Skip to content

Commit 4f4447e

Browse files
baumanjkinetiknz
authored andcommitted
If the iloc size is corrupt, return an Err rather than asserting
See https://bugzilla.mozilla.org/show_bug.cgi?id=1655846
1 parent 778d47d commit 4f4447e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

mp4parse/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,9 +1603,11 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
16031603
})?;
16041604
}
16051605

1606-
debug_assert_eq!(iloc.remaining(), 0);
1607-
1608-
Ok(items)
1606+
if iloc.remaining() == 0 {
1607+
Ok(items)
1608+
} else {
1609+
Err(Error::InvalidData("invalid iloc size"))
1610+
}
16091611
}
16101612

16111613
/// Read the contents of a box, including sub boxes.

mp4parse/tests/bug-1655846.avif

256 Bytes
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static AUDIO_EME_CBCS_MP4: &str = "tests/bipbop_cbcs_audio_init.mp4";
2828
static VIDEO_EME_CBCS_MP4: &str = "tests/bipbop_cbcs_video_init.mp4";
2929
static VIDEO_AV1_MP4: &str = "tests/tiny_av1.mp4";
3030
static IMAGE_AVIF: &str = "av1-avif/testFiles/Microsoft/Monochrome.avif";
31+
static IMAGE_AVIF_CORRUPT: &str = "tests/bug-1655846.avif";
3132
static IMAGE_AVIF_GRID: &str = "av1-avif/testFiles/Microsoft/Summer_in_Tomsk_720p_5x4_grid.avif";
3233
static AVIF_TEST_DIR: &str = "av1-avif/testFiles";
3334

@@ -627,6 +628,13 @@ fn public_avif_primary_item() {
627628
assert_eq!(context.primary_item[0..4], [0x12, 0x00, 0x0a, 0x0a]);
628629
}
629630

631+
#[test]
632+
fn public_avif_bug_1655846() {
633+
let context = &mut mp4::AvifContext::new();
634+
let input = &mut File::open(IMAGE_AVIF_CORRUPT).expect("Unknown file");
635+
assert!(mp4::read_avif(input, context).is_err());
636+
}
637+
630638
#[test]
631639
#[ignore] // Remove when we add support; see https://github.com/mozilla/mp4parse-rust/issues/198
632640
fn public_avif_primary_item_is_grid() {

0 commit comments

Comments
 (0)