@@ -804,7 +804,7 @@ struct AvifMeta {
804
804
item_references : TryVec < SingleItemTypeReferenceBox > ,
805
805
properties : TryVec < AssociatedProperty > ,
806
806
primary_item_id : u32 ,
807
- iloc_items : TryVec < ItemLocationBoxItem > ,
807
+ iloc_items : TryHashMap < u32 , ItemLocationBoxItem > ,
808
808
}
809
809
810
810
/// A Media Data Box
@@ -1060,7 +1060,6 @@ impl TryFrom<u8> for IlocVersion {
1060
1060
/// `data_reference_index` is omitted, since only 0 (i.e., this file) is supported
1061
1061
#[ derive( Debug ) ]
1062
1062
struct ItemLocationBoxItem {
1063
- item_id : u32 ,
1064
1063
construction_method : ConstructionMethod ,
1065
1064
/// Unused for ConstructionMethod::Idat
1066
1065
extents : TryVec < Extent > ,
@@ -1449,10 +1448,10 @@ pub fn read_avif<T: Read>(f: &mut T) -> Result<AvifContext> {
1449
1448
let mut alpha_item = None ;
1450
1449
1451
1450
// 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 {
1454
1453
& mut primary_item
1455
- } else if Some ( loc . item_id ) == alpha_item_id {
1454
+ } else if Some ( item_id) == alpha_item_id {
1456
1455
& mut alpha_item
1457
1456
} else {
1458
1457
continue ;
@@ -2118,7 +2117,7 @@ fn read_auxc<T: Read>(src: &mut BMFFBox<T>) -> Result<AuxiliaryTypeProperty> {
2118
2117
2119
2118
/// Parse an item location box inside a meta box
2120
2119
/// 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 > > {
2122
2121
let version: IlocVersion = read_fullbox_version_no_flags ( src) ?. try_into ( ) ?;
2123
2122
2124
2123
let iloc = src. read_into_try_vec ( ) ?;
@@ -2141,7 +2140,7 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
2141
2140
IlocVersion :: Two => iloc. read_u32 ( 32 ) ?,
2142
2141
} ;
2143
2142
2144
- let mut items = TryVec :: with_capacity ( item_count. to_usize ( ) ) ?;
2143
+ let mut items = TryHashMap :: with_capacity ( item_count. to_usize ( ) ) ?;
2145
2144
2146
2145
for _ in 0 ..item_count {
2147
2146
let item_id = match version {
@@ -2230,11 +2229,14 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemLocationBoxItem
2230
2229
extents. push ( extent) ?;
2231
2230
}
2232
2231
2233
- items. push ( ItemLocationBoxItem {
2234
- item_id,
2232
+ let loc = ItemLocationBoxItem {
2235
2233
construction_method,
2236
2234
extents,
2237
- } ) ?;
2235
+ } ;
2236
+
2237
+ if items. insert ( item_id, loc) ?. is_some ( ) {
2238
+ return Err ( Error :: InvalidData ( "duplicate item_ID in iloc" ) ) ;
2239
+ }
2238
2240
}
2239
2241
2240
2242
if iloc. remaining ( ) == 0 {
0 commit comments