@@ -770,8 +770,6 @@ static void avifMetaDestroy(avifMeta * meta)
770770 avifFree (meta );
771771}
772772
773- // CAUTION: This function could potentially resize the meta->items array thereby invalidating all existing pointers that are being
774- // stored locally. So if this function is being called, exercise caution in the caller to not use invalid pointers.
775773static avifDecoderItem * avifMetaFindItem (avifMeta * meta , uint32_t itemID )
776774{
777775 if (itemID == 0 ) {
@@ -3620,20 +3618,17 @@ static avifBool avifDecoderItemIsAlphaAux(avifDecoderItem * item, uint32_t color
36203618 return auxCProp && isAlphaURN (auxCProp -> u .auxC .auxType );
36213619}
36223620
3623- // Finds the alpha item whose parent item is *colorItemPtr and sets it in the alphaItem output parameter. Returns AVIF_RESULT_OK
3624- // on success. Note that *alphaItem can be NULL even if the return value is AVIF_RESULT_OK. If the *colorItemPtr is a grid and the
3625- // alpha item is represented as a set of auxl items to each color tile, then a fake item will be created and *isAlphaItemInInput
3626- // will be set to AVIF_FALSE. In this case, the alpha item merely exists to hold the locations of the alpha tile items. The data
3627- // of this item need not be read and the pixi property cannot be validated. Otherwise, *isAlphaItemInInput will be set to
3628- // AVIF_TRUE when *alphaItem is not NULL. If the data->meta->items array is resized, then the value in *colorItemPtr could become
3629- // invalid. This function also resets *colorItemPtr to the right value if an alpha item was found and added to the data->meta->items
3630- // array.
3621+ // Finds the alpha item whose parent item is colorItem and sets it in the alphaItem output parameter. Returns AVIF_RESULT_OK on
3622+ // success. Note that *alphaItem can be NULL even if the return value is AVIF_RESULT_OK. If the colorItem is a grid and the alpha
3623+ // item is represented as a set of auxl items to each color tile, then a fake item will be created and *isAlphaItemInInput will be
3624+ // set to AVIF_FALSE. In this case, the alpha item merely exists to hold the locations of the alpha tile items. The data of this
3625+ // item need not be read and the pixi property cannot be validated. Otherwise, *isAlphaItemInInput will be set to AVIF_TRUE when
3626+ // *alphaItem is not NULL.
36313627static avifResult avifDecoderDataFindAlphaItem (avifDecoderData * data ,
3632- avifDecoderItem * * colorItemPtr ,
3628+ avifDecoderItem * colorItem ,
36333629 avifDecoderItem * * alphaItem ,
36343630 avifBool * isAlphaItemInInput )
36353631{
3636- const avifDecoderItem * colorItem = * colorItemPtr ;
36373632 for (uint32_t itemIndex = 0 ; itemIndex < data -> meta -> items .count ; ++ itemIndex ) {
36383633 avifDecoderItem * item = data -> meta -> items .item [itemIndex ];
36393634 if (avifDecoderItemShouldBeSkipped (item )) {
@@ -3695,26 +3690,12 @@ static avifResult avifDecoderDataFindAlphaItem(avifDecoderData * data,
36953690 }
36963691 }
36973692 assert (alphaItemCount == colorItemCount );
3698-
3699- int colorItemIndex = -1 ;
3700- for (uint32_t i = 0 ; i < data -> meta -> items .count ; ++ i ) {
3701- if (colorItem -> id == data -> meta -> items .item [i ]-> id ) {
3702- colorItemIndex = i ;
3703- break ;
3704- }
3705- }
3706- assert (colorItemIndex >= 0 );
3707-
37083693 * alphaItem = avifMetaFindItem (colorItem -> meta , maxItemID + 1 );
37093694 if (* alphaItem == NULL ) {
37103695 avifFree (alphaItemIndices );
37113696 * isAlphaItemInInput = AVIF_FALSE ;
37123697 return AVIF_RESULT_OUT_OF_MEMORY ;
37133698 }
3714- // avifMetaFindItem() could invalidate all existing item pointers. So reset the colorItem pointers.
3715- * colorItemPtr = data -> meta -> items .item [colorItemIndex ];
3716- colorItem = * colorItemPtr ;
3717-
37183699 memcpy ((* alphaItem )-> type , "grid" , 4 );
37193700 (* alphaItem )-> width = colorItem -> width ;
37203701 (* alphaItem )-> height = colorItem -> height ;
@@ -3942,6 +3923,7 @@ avifResult avifDecoderReset(avifDecoder * decoder)
39423923 avifDiagnosticsPrintf (& decoder -> diag , "Primary item not found" );
39433924 return AVIF_RESULT_MISSING_IMAGE_ITEM ;
39443925 }
3926+ colorProperties = & colorItem -> properties ;
39453927 if (!memcmp (colorItem -> type , "grid" , 4 )) {
39463928 avifROData readData ;
39473929 AVIF_CHECKRES (avifDecoderItemRead (colorItem , decoder -> io , & readData , 0 , 0 , data -> diag ));
@@ -3973,7 +3955,7 @@ avifResult avifDecoderReset(avifDecoder * decoder)
39733955
39743956 avifBool isAlphaItemInInput ;
39753957 avifDecoderItem * alphaItem ;
3976- AVIF_CHECKRES (avifDecoderDataFindAlphaItem (data , & colorItem , & alphaItem , & isAlphaItemInInput ));
3958+ AVIF_CHECKRES (avifDecoderDataFindAlphaItem (data , colorItem , & alphaItem , & isAlphaItemInInput ));
39773959 avifCodecType alphaCodecType = AVIF_CODEC_TYPE_UNKNOWN ;
39783960 if (alphaItem ) {
39793961 if (!memcmp (alphaItem -> type , "grid" , 4 )) {
@@ -3998,8 +3980,6 @@ avifResult avifDecoderReset(avifDecoder * decoder)
39983980 }
39993981 }
40003982
4001- colorProperties = & colorItem -> properties ;
4002-
40033983 // Find Exif and/or XMP metadata, if any
40043984 AVIF_CHECKRES (avifDecoderFindMetadata (decoder , data -> meta , decoder -> image , colorItem -> id ));
40053985
0 commit comments