Skip to content

Commit 9768879

Browse files
Zaggy1024kinetiknz
authored andcommitted
Remove error for when an AVIF has no iloc box.
Item locations can be omitted for AVIS-major files which don't contain `pitm` boxes. When no `iloc` is present, the locations map is default-initialized, and if the `pitm` references a nonexistent item, an error is thrown in strict mode.
1 parent b293867 commit 9768879

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

mp4parse/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ pub enum Status {
222222
IlocBadQuantity,
223223
IlocBadSize,
224224
IlocDuplicateItemId,
225-
IlocMissing,
226225
IlocNotFound,
227226
IlocOffsetOverflow,
228227
ImageItemType,
@@ -260,6 +259,7 @@ pub enum Status {
260259
NoImage,
261260
PitmBadQuantity,
262261
PitmMissing,
262+
PitmNotFound,
263263
PixiBadChannelCount,
264264
PixiMissing,
265265
PsshSizeOverflow,
@@ -597,9 +597,6 @@ impl From<Status> for &str {
597597
Status::IlocDuplicateItemId => {
598598
"duplicate item_ID in iloc"
599599
}
600-
Status::IlocMissing => {
601-
"iloc missing"
602-
}
603600
Status::IlocNotFound => {
604601
"ItemLocationBox (iloc) contains an extent not present in any mdat or idat box"
605602
}
@@ -732,6 +729,9 @@ impl From<Status> for &str {
732729
"Missing required PrimaryItemBox (pitm), required \
733730
per HEIF (ISO/IEC 23008-12:2017) § 10.2.1"
734731
}
732+
Status::PitmNotFound => {
733+
"PrimaryItemBox (pitm) referenced an item ID that was not present"
734+
}
735735
Status::PixiBadChannelCount => {
736736
"invalid num_channels"
737737
}
@@ -2708,6 +2708,12 @@ pub fn read_avif<T: Read>(f: &mut T, strictness: ParseStrictness) -> Result<Avif
27082708
assert!(item.is_some());
27092709
}
27102710

2711+
if (primary_item_id.is_some() && primary_item.is_none())
2712+
|| (alpha_item_id.is_some() && alpha_item.is_none())
2713+
{
2714+
fail_with_status_if(strictness == ParseStrictness::Strict, Status::PitmNotFound)?;
2715+
}
2716+
27112717
assert!(primary_item.is_none() || primary_item_id.is_some());
27122718
assert!(alpha_item.is_none() || alpha_item_id.is_some());
27132719

@@ -2918,7 +2924,7 @@ fn read_avif_meta<T: Read + Offset>(
29182924
item_references: item_references.unwrap_or_default(),
29192925
primary_item_id,
29202926
item_infos: item_infos.unwrap_or_default(),
2921-
iloc_items: iloc_items.ok_or_else(|| Error::from(Status::IlocMissing))?,
2927+
iloc_items: iloc_items.unwrap_or_default(),
29222928
item_data_box,
29232929
})
29242930
}
1.57 KB
Binary file not shown.
1.59 KB
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static AVIF_AVIS_MAJOR_NO_PITM: &str =
8686
/// This is av1-avif/testFiles/Netflix/avis/alpha_video.avif
8787
/// but with https://github.com/AOMediaCodec/av1-avif/issues/177 fixed
8888
static AVIF_AVIS_MAJOR_WITH_PITM_AND_ALPHA: &str = "tests/alpha_video_fixed.avif";
89+
static AVIF_AVIS_WITH_NO_PITM_NO_ILOC: &str = "tests/avis_with_no_ptim_no_iloc.avif";
90+
static AVIF_AVIS_WITH_PITM_NO_ILOC: &str = "tests/avis_with_pitm_no_iloc.avif";
8991
static AVIF_AVIS_MAJOR_NO_MOOV: &str = "tests/corrupt/alpha_video_moov_is_moop.avif";
9092
static AVIF_AVIS_NO_LOOP: &str = "tests/loop_none.avif";
9193
static AVIF_AVIS_LOOP_FOREVER: &str = "tests/loop_forever.avif";
@@ -1240,6 +1242,17 @@ fn public_avif_avis_major_no_moov() {
12401242
assert_avif_shall(AVIF_AVIS_MAJOR_NO_MOOV, Status::MoovMissing);
12411243
}
12421244

1245+
#[test]
1246+
fn public_avif_avis_with_no_pitm_no_iloc() {
1247+
let input = &mut File::open(AVIF_AVIS_WITH_NO_PITM_NO_ILOC).expect("Unknown file");
1248+
assert!(mp4::read_avif(input, ParseStrictness::Normal).is_ok());
1249+
}
1250+
1251+
#[test]
1252+
fn public_avif_avis_with_pitm_no_iloc() {
1253+
assert_avif_should(AVIF_AVIS_WITH_PITM_NO_ILOC, Status::PitmNotFound);
1254+
}
1255+
12431256
fn public_avis_loop_impl(path: &str, looped: bool) {
12441257
let input = &mut File::open(path).expect("Unknown file");
12451258
match mp4::read_avif(input, ParseStrictness::Normal) {

0 commit comments

Comments
 (0)