Skip to content

Commit a7eb5eb

Browse files
committed
Enforce singular iprp and iref
1 parent b1860f0 commit a7eb5eb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

mp4parse/src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,8 @@ fn read_avif_meta<T: Read + Offset>(src: &mut BMFFBox<T>) -> Result<AvifMeta> {
13541354
let mut primary_item_id = None;
13551355
let mut item_infos = None;
13561356
let mut iloc_items = None;
1357-
let mut item_references = TryVec::new();
1358-
let mut properties = TryVec::new();
1357+
let mut item_references = None;
1358+
let mut properties = None;
13591359

13601360
let mut iter = src.box_iter();
13611361
while let Some(mut b) = iter.next_box()? {
@@ -1379,16 +1379,22 @@ fn read_avif_meta<T: Read + Offset>(src: &mut BMFFBox<T>) -> Result<AvifMeta> {
13791379
BoxType::PrimaryItemBox => {
13801380
if primary_item_id.is_some() {
13811381
return Err(Error::InvalidData(
1382-
"There should be zero or one iloc boxes per ISO 14496-12:2015 § 8.11.4.1",
1382+
"There should be zero or one pitm boxes per ISO 14496-12:2015 § 8.11.4.1",
13831383
));
13841384
}
13851385
primary_item_id = Some(read_pitm(&mut b)?);
13861386
}
13871387
BoxType::ImageReferenceBox => {
1388-
item_references = read_iref(&mut b)?;
1388+
if item_references.is_some() {
1389+
return Err(Error::InvalidData("There should be zero or one iref boxes"));
1390+
}
1391+
item_references = Some(read_iref(&mut b)?);
13891392
}
13901393
BoxType::ImagePropertiesBox => {
1391-
properties = read_iprp(&mut b)?;
1394+
if properties.is_some() {
1395+
return Err(Error::InvalidData("There should be zero or one iprp boxes"));
1396+
}
1397+
properties = Some(read_iprp(&mut b)?);
13921398
}
13931399
_ => skip_box_content(&mut b)?,
13941400
}
@@ -1414,8 +1420,8 @@ fn read_avif_meta<T: Read + Offset>(src: &mut BMFFBox<T>) -> Result<AvifMeta> {
14141420
}
14151421

14161422
Ok(AvifMeta {
1417-
properties,
1418-
item_references,
1423+
properties: properties.unwrap_or_else(TryVec::new),
1424+
item_references: item_references.unwrap_or_else(TryVec::new),
14191425
primary_item_id,
14201426
iloc_items: iloc_items.ok_or(Error::InvalidData("iloc missing"))?,
14211427
})

0 commit comments

Comments
 (0)