Skip to content

Commit d32b098

Browse files
baumanjkornelski
authored andcommitted
iref reading improvements
1 parent a78e441 commit d32b098

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

mp4parse/src/lib.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl AvifContext {
762762
}
763763

764764
struct AvifMeta {
765-
item_references: TryVec<ItemReferenceEntry>,
765+
item_references: TryVec<SingleItemTypeReferenceBox>,
766766
properties: TryVec<AssociatedProperty>,
767767
primary_item_id: u32,
768768
iloc_items: TryVec<ItemLocationBoxItem>,
@@ -844,7 +844,7 @@ struct ItemInfoEntry {
844844

845845
/// See ISO 14496-12:2015 § 8.11.12
846846
#[derive(Debug)]
847-
struct ItemReferenceEntry {
847+
struct SingleItemTypeReferenceBox {
848848
item_type: FourCC,
849849
from_item_id: u32,
850850
to_item_id: u32,
@@ -1508,8 +1508,8 @@ fn read_infe<T: Read>(src: &mut BMFFBox<T>) -> Result<ItemInfoEntry> {
15081508
Ok(ItemInfoEntry { item_id, item_type })
15091509
}
15101510

1511-
fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemReferenceEntry>> {
1512-
let mut entries = TryVec::new();
1511+
fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<SingleItemTypeReferenceBox>> {
1512+
let mut item_references = TryVec::new();
15131513
let version = read_fullbox_version_no_flags(src)?;
15141514
if version > 1 {
15151515
return Err(Error::Unsupported("iref version"));
@@ -1518,25 +1518,31 @@ fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemReferenceEntry>
15181518
let mut iter = src.box_iter();
15191519
while let Some(mut b) = iter.next_box()? {
15201520
let from_item_id = if version == 0 {
1521-
be_u16(&mut b)? as u32
1521+
be_u16(&mut b)?.into()
15221522
} else {
15231523
be_u32(&mut b)?
15241524
};
1525-
let item_count = be_u16(&mut b)?;
1526-
for _ in 0..item_count {
1525+
let reference_count = be_u16(&mut b)?;
1526+
for _ in 0..reference_count {
15271527
let to_item_id = if version == 0 {
15281528
be_u16(&mut b)? as u32
15291529
} else {
15301530
be_u32(&mut b)?
15311531
};
1532-
entries.push(ItemReferenceEntry {
1532+
if from_item_id == to_item_id {
1533+
return Err(Error::InvalidData(
1534+
"from_item_id and to_item_id must be different",
1535+
));
1536+
}
1537+
item_references.push(SingleItemTypeReferenceBox {
15331538
item_type: b.head.name.into(),
15341539
from_item_id,
15351540
to_item_id,
15361541
})?;
15371542
}
1543+
check_parser_state!(b.content);
15381544
}
1539-
Ok(entries)
1545+
Ok(item_references)
15401546
}
15411547

15421548
fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>> {

0 commit comments

Comments
 (0)