Skip to content

Commit 365fe4b

Browse files
authored
Merge pull request mozilla#256 from mozilla/ipma-validate-moar
Add one last ipma validity check
2 parents 4d48ff9 + bb6cd1a commit 365fe4b

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

mp4parse/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,12 +1758,15 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
17581758
return Err(Error::InvalidData("unexpected iprp child"));
17591759
}
17601760

1761-
let version_and_flags = read_fullbox_extra(&mut b)?;
1762-
if ipma_version_and_flag_values_seen.contains(&version_and_flags) {
1761+
let (version, flags) = read_fullbox_extra(&mut b)?;
1762+
if ipma_version_and_flag_values_seen.contains(&(version, flags)) {
17631763
return Err(Error::InvalidData("Duplicate ipma with same version/flags"));
17641764
}
1765-
ipma_version_and_flag_values_seen.push(version_and_flags)?;
1766-
let associations = read_ipma(&mut b, version_and_flags)?;
1765+
if flags != 0 && properties.len() <= 127 {
1766+
return Err(Error::InvalidData("flags should be equal to 0 unless there are more than 127 properties in the ItemPropertyContainerBox"));
1767+
}
1768+
ipma_version_and_flag_values_seen.push((version, flags))?;
1769+
let associations = read_ipma(&mut b, version, flags)?;
17671770
for a in associations {
17681771
if a.property_index == 0 {
17691772
if a.essential {
@@ -1965,7 +1968,8 @@ fn calculate_ipma_total_associations(
19651968
/// See HEIF (ISO 23008-12:2017) § 9.3.1
19661969
fn read_ipma<T: Read>(
19671970
src: &mut BMFFBox<T>,
1968-
(version, flags): (u8, u32),
1971+
version: u8,
1972+
flags: u32,
19691973
) -> Result<TryVec<Association>> {
19701974
let entry_count = be_u32(src)?;
19711975
let num_association_bytes =
437 Bytes
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static IMAGE_AVIF_EXTENTS: &str = "tests/kodim-extents.avif";
3333
static IMAGE_AVIF_CORRUPT: &str = "tests/corrupt/bug-1655846.avif";
3434
static IMAGE_AVIF_CORRUPT_2: &str = "tests/corrupt/bug-1661347.avif";
3535
static IMAGE_AVIF_CORRUPT_3: &str = "tests/corrupt/bad-ipma-version.avif";
36+
static IMAGE_AVIF_CORRUPT_4: &str = "tests/corrupt/bad-ipma-flags.avif";
3637
static IMAGE_AVIF_GRID: &str = "av1-avif/testFiles/Microsoft/Summer_in_Tomsk_720p_5x4_grid.avif";
3738
static AVIF_TEST_DIRS: &[&str] = &["tests", "av1-avif/testFiles"];
3839
static AVIF_CORRUPT_IMAGES: &str = "tests/corrupt";
@@ -643,11 +644,8 @@ fn public_avif_bug_1661347() {
643644
assert!(mp4::read_avif(input).is_err());
644645
}
645646

646-
#[test]
647-
fn public_avif_bad_ipma_version() {
648-
let input = &mut File::open(IMAGE_AVIF_CORRUPT_3).expect("Unknown file");
649-
let expected_msg = "The version 0 should be used unless 32-bit item_ID values are needed";
650-
match mp4::read_avif(input) {
647+
fn assert_invalid_data<T: std::fmt::Debug>(result: mp4::Result<T>, expected_msg: &str) {
648+
match result {
651649
Err(Error::InvalidData(msg)) if msg == expected_msg => {}
652650
r => panic!(
653651
"Expected Err(Error::InvalidData({:?})), found {:?}",
@@ -656,6 +654,20 @@ fn public_avif_bad_ipma_version() {
656654
}
657655
}
658656

657+
#[test]
658+
fn public_avif_bad_ipma_version() {
659+
let input = &mut File::open(IMAGE_AVIF_CORRUPT_3).expect("Unknown file");
660+
let expected_msg = "The version 0 should be used unless 32-bit item_ID values are needed";
661+
assert_invalid_data(mp4::read_avif(input), expected_msg);
662+
}
663+
664+
#[test]
665+
fn public_avif_bad_ipma_flags() {
666+
let input = &mut File::open(IMAGE_AVIF_CORRUPT_4).expect("Unknown file");
667+
let expected_msg = "flags should be equal to 0 unless there are more than 127 properties in the ItemPropertyContainerBox";
668+
assert_invalid_data(mp4::read_avif(input), expected_msg);
669+
}
670+
659671
#[test]
660672
#[ignore] // Remove when we add support; see https://github.com/mozilla/mp4parse-rust/issues/198
661673
fn public_avif_primary_item_is_grid() {

0 commit comments

Comments
 (0)