@@ -1548,7 +1548,7 @@ fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<SingleItemTypeRefer
1548
1548
1549
1549
fn read_iprp < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryVec < AssociatedProperty > > {
1550
1550
let mut iter = src. box_iter ( ) ;
1551
- let mut properties = TryVec :: new ( ) ;
1551
+ let mut properties = TryHashMap :: with_capacity ( 1 ) ? ;
1552
1552
let mut associations = TryVec :: new ( ) ;
1553
1553
1554
1554
while let Some ( mut b) = iter. next_box ( ) ? {
@@ -1565,19 +1565,21 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
1565
1565
1566
1566
let mut associated = TryVec :: new ( ) ;
1567
1567
for a in associations {
1568
- let index = match a. property_index {
1569
- 0 => continue ,
1570
- x => x as usize - 1 ,
1571
- } ;
1572
- if let Some ( prop) = properties. get ( index) {
1573
- if * prop != ItemProperty :: Unsupported {
1574
- associated. push ( AssociatedProperty {
1575
- item_id : a. item_id ,
1576
- property : prop. try_clone ( ) ?,
1577
- } ) ?;
1568
+ if a. property_index == 0 {
1569
+ if a. essential {
1570
+ return Err ( Error :: InvalidData ( "0 property index can't be essential" ) ) ;
1578
1571
}
1572
+ continue ;
1573
+ }
1574
+
1575
+ if let Some ( prop) = properties. get ( & a. property_index ) {
1576
+ associated. push ( AssociatedProperty {
1577
+ item_id : a. item_id ,
1578
+ property : prop. try_clone ( ) ?,
1579
+ } ) ?;
1579
1580
}
1580
1581
}
1582
+
1581
1583
Ok ( associated)
1582
1584
}
1583
1585
@@ -1638,21 +1640,28 @@ fn read_ipma<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<Association>> {
1638
1640
Ok ( associations)
1639
1641
}
1640
1642
1641
- fn read_ipco < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryVec < ItemProperty > > {
1642
- let mut properties = TryVec :: new ( ) ;
1643
+ fn read_ipco < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryHashMap < u16 , ItemProperty > > {
1644
+ let mut properties = TryHashMap :: with_capacity ( 1 ) ? ;
1643
1645
1646
+ let mut index = 1 ; // ipma uses 1-based indexing
1644
1647
let mut iter = src. box_iter ( ) ;
1645
1648
while let Some ( mut b) = iter. next_box ( ) ? {
1646
- // Must push for every property to have correct index for them
1647
- properties. push ( match b. head . name {
1648
- BoxType :: PixelInformationBox => ItemProperty :: Channels ( read_pixi ( & mut b) ?) ,
1649
- BoxType :: AuxiliaryTypeProperty => ItemProperty :: AuxiliaryType ( read_auxc ( & mut b) ?) ,
1649
+ if let Some ( property) = match b. head . name {
1650
+ BoxType :: PixelInformationBox => Some ( ItemProperty :: Channels ( read_pixi ( & mut b) ?) ) ,
1651
+ BoxType :: AuxiliaryTypeProperty => Some ( ItemProperty :: AuxiliaryType ( read_auxc ( & mut b) ?) ) ,
1650
1652
_ => {
1651
1653
skip_box_remain ( & mut b) ?;
1652
- ItemProperty :: Unsupported
1654
+ None
1653
1655
}
1654
- } ) ?;
1656
+ } {
1657
+ properties. insert ( index, property) ?;
1658
+ }
1659
+
1660
+ index += 1 ; // must include ignored properties to have correct indexes
1661
+
1662
+ check_parser_state ! ( b. content) ;
1655
1663
}
1664
+
1656
1665
Ok ( properties)
1657
1666
}
1658
1667
0 commit comments