Add the AVIF_STRICT_ALPHA_ISPE_REQUIRED flag To allow alpha auxiliary image items to not have an ispe property, clear the AVIF_STRICT_ALPHA_ISPE_REQUIRED bit in decoder->strictFlags. Update the bug numbers in comments.
diff --git a/include/avif/avif.h b/include/avif/avif.h index 124d173..e4f01c6 100644 --- a/include/avif/avif.h +++ b/include/avif/avif.h
@@ -723,8 +723,16 @@ // function returns AVIF_FALSE and this strict flag is set, the decode will fail. AVIF_STRICT_CLAP_VALID = (1 << 1), + // Requires the ImageSpatialExtentsProperty ('ispe') be present in alpha auxiliary image items. + // avif-serialize 0.7.3 or older does not add the 'ispe' item property to alpha auxiliary image + // items. If you need to decode AVIF images encoded by the cavif encoder with avif-serialize + // 0.7.3 or older, be sure to disable this bit. (This issue has been corrected in avif-serialize + // 0.7.4.) See https://github.com/kornelski/avif-serialize/issues/3 and + // https://crbug.com/1246678. + AVIF_STRICT_ALPHA_ISPE_REQUIRED = (1 << 2), + // Maximum strictness; enables all bits above. This is avifDecoder's default. - AVIF_STRICT_ENABLED = AVIF_STRICT_PIXI_REQUIRED | AVIF_STRICT_CLAP_VALID + AVIF_STRICT_ENABLED = AVIF_STRICT_PIXI_REQUIRED | AVIF_STRICT_CLAP_VALID | AVIF_STRICT_ALPHA_ISPE_REQUIRED } avifStrictFlag; typedef uint32_t avifStrictFlags;
diff --git a/src/read.c b/src/read.c index ad22f0b..3b38148 100644 --- a/src/read.c +++ b/src/read.c
@@ -3101,9 +3101,19 @@ avifDiagnosticsPrintf(data->diag, "Item ID [%u] size is too large [%ux%u]", item->id, item->width, item->height); return AVIF_RESULT_BMFF_PARSE_FAILED; } - } else if (!item->auxForID) { // NON-STANDARD: Allow auxiliary images to not have an ispe property. See: https://crbug.com/1245673 - avifDiagnosticsPrintf(data->diag, "Item ID [%u] is missing a mandatory ispe property", item->id); - return AVIF_RESULT_BMFF_PARSE_FAILED; + } else { + const avifProperty * auxCProp = avifPropertyArrayFind(&item->properties, "auxC"); + if (auxCProp && isAlphaURN(auxCProp->u.auxC.auxType)) { + if (decoder->strictFlags & AVIF_STRICT_ALPHA_ISPE_REQUIRED) { + avifDiagnosticsPrintf(data->diag, + "[Strict] Alpha auxiliary image item ID [%u] is missing a mandatory ispe property", + item->id); + return AVIF_RESULT_BMFF_PARSE_FAILED; + } + } else { + avifDiagnosticsPrintf(data->diag, "Item ID [%u] is missing a mandatory ispe property", item->id); + return AVIF_RESULT_BMFF_PARSE_FAILED; + } } } return avifDecoderReset(decoder); @@ -3428,7 +3438,7 @@ if (alphaItem) { if (!alphaItem->width && !alphaItem->height) { // NON-STANDARD: Alpha subimage does not have an ispe property; adopt width/height from color item - // See: https://crbug.com/1245673 + assert(!(decoder->strictFlags & AVIF_STRICT_ALPHA_ISPE_REQUIRED)); alphaItem->width = colorItem->width; alphaItem->height = colorItem->height; }