Skip to content

Commit c918d72

Browse files
authored
Merge pull request mozilla#255 from mozilla/ossfuzz-28160
Return error if iloc box contains duplicate item_ID
2 parents 365fe4b + d06b166 commit c918d72

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mp4parse/src/lib.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ struct AvifMeta {
804804
item_references: TryVec<SingleItemTypeReferenceBox>,
805805
properties: TryVec<AssociatedProperty>,
806806
primary_item_id: u32,
807-
iloc_items: TryVec<ItemLocationBoxItem>,
807+
iloc_items: TryHashMap<u32, ItemLocationBoxItem>,
808808
}
809809

810810
/// A Media Data Box
@@ -1060,7 +1060,6 @@ impl TryFrom<u8> for IlocVersion {
10601060
/// `data_reference_index` is omitted, since only 0 (i.e., this file) is supported
10611061
#[derive(Debug)]
10621062
struct ItemLocationBoxItem {
1063-
item_id: u32,
10641063
construction_method: ConstructionMethod,
10651064
/// Unused for ConstructionMethod::Idat
10661065
extents: TryVec<Extent>,
@@ -1449,10 +1448,10 @@ pub fn read_avif<T: Read>(f: &mut T) -> Result<AvifContext> {
14491448
let mut alpha_item = None;
14501449

14511450
// store data or record location of relevant items
1452-
for loc in meta.iloc_items {
1453-
let item = if loc.item_id == meta.primary_item_id {
1451+
for (item_id, loc) in meta.iloc_items {
1452+
let item = if item_id == meta.primary_item_id {
14541453
&mut primary_item
1455-
} else if Some(loc.item_id) == alpha_item_id {
1454+
} else if Some(item_id) == alpha_item_id {
14561455
&mut alpha_item
14571456
} else {
14581457
continue;
@@ -2118,7 +2117,7 @@ fn read_auxc<T: Read>(src: &mut BMFFBox<T>) -> Result<AuxiliaryTypeProperty> {
21182117

21192118
/// Parse an item location box inside a meta box
21202119
/// See ISOBMFF (ISO 14496-12:2015) § 8.11.3
2121-
fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem>> {
2120+
fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryHashMap<u32, ItemLocationBoxItem>> {
21222121
let version: IlocVersion = read_fullbox_version_no_flags(src)?.try_into()?;
21232122

21242123
let iloc = src.read_into_try_vec()?;
@@ -2141,7 +2140,7 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
21412140
IlocVersion::Two => iloc.read_u32(32)?,
21422141
};
21432142

2144-
let mut items = TryVec::with_capacity(item_count.to_usize())?;
2143+
let mut items = TryHashMap::with_capacity(item_count.to_usize())?;
21452144

21462145
for _ in 0..item_count {
21472146
let item_id = match version {
@@ -2230,11 +2229,14 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
22302229
extents.push(extent)?;
22312230
}
22322231

2233-
items.push(ItemLocationBoxItem {
2234-
item_id,
2232+
let loc = ItemLocationBoxItem {
22352233
construction_method,
22362234
extents,
2237-
})?;
2235+
};
2236+
2237+
if items.insert(item_id, loc)?.is_some() {
2238+
return Err(Error::InvalidData("duplicate item_ID in iloc"));
2239+
}
22382240
}
22392241

22402242
if iloc.remaining() == 0 {

0 commit comments

Comments
 (0)