Ignore all items containing 'essential' properties that libavif doesn't support/implement
diff --git a/src/read.c b/src/read.c
index bae84cd..2a63948 100644
--- a/src/read.c
+++ b/src/read.c
@@ -103,6 +103,7 @@
uint32_t auxForID; // if non-zero, this item is an auxC plane for Item #{auxForID}
uint32_t descForID; // if non-zero, this item is a content description for Item #{descForID}
uint32_t dimgForID; // if non-zero, this item is a derived image for Item #{dimgForID}
+ avifBool hasUnsupportedEssentialProperty; // If true, this file cites a property flagged as 'essential' that libavif doesn't support (yet). Ignore the item, if so.
} avifDecoderItem;
AVIF_ARRAY_DECLARE(avifDecoderItemArray, avifDecoderItem, item);
@@ -519,6 +520,10 @@
if (memcmp(item->type, "av01", 4)) {
continue;
}
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
++tilesAvailable;
}
@@ -534,6 +539,10 @@
if (memcmp(item->type, "av01", 4)) {
continue;
}
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
avifTile * tile = avifDecoderDataCreateTile(data);
avifSample * sample = (avifSample *)avifArrayPushPtr(&tile->input->samples);
@@ -1015,16 +1024,16 @@
uint8_t associationCount;
CHECK(avifROStreamRead(&s, &associationCount, 1));
for (uint8_t associationIndex = 0; associationIndex < associationCount; ++associationIndex) {
- // avifBool essential = AVIF_FALSE; // currently unused
+ avifBool essential = AVIF_FALSE;
uint16_t propertyIndex = 0;
if (propertyIndexIsU16) {
CHECK(avifROStreamReadU16(&s, &propertyIndex));
- // essential = ((propertyIndex & 0x8000) != 0);
+ essential = ((propertyIndex & 0x8000) != 0);
propertyIndex &= 0x7fff;
} else {
uint8_t tmp;
CHECK(avifROStreamRead(&s, &tmp, 1));
- // essential = ((tmp & 0x80) != 0);
+ essential = ((tmp & 0x80) != 0);
propertyIndex = tmp & 0x7f;
}
@@ -1069,6 +1078,12 @@
} else if (!memcmp(prop->type, "imir", 4)) {
item->imirPresent = AVIF_TRUE;
memcpy(&item->imir, &prop->imir, sizeof(avifImageMirror));
+ } else {
+ if (essential) {
+ // Discovered an essential item property that libavif doesn't support!
+ // Make a note to ignore this item later.
+ item->hasUnsupportedEssentialProperty = AVIF_TRUE;
+ }
}
}
}
@@ -1819,6 +1834,10 @@
// Sanity check items
for (uint32_t itemIndex = 0; itemIndex < decoder->data->items.count; ++itemIndex) {
avifDecoderItem * item = &decoder->data->items.item[itemIndex];
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
const uint8_t * p = avifDecoderDataCalcItemPtr(decoder->data, item);
if (p == NULL) {
return AVIF_RESULT_BMFF_PARSE_FAILED;
@@ -2002,6 +2021,10 @@
if (!item->id || !item->size) {
break;
}
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
avifBool isGrid = (memcmp(item->type, "grid", 4) == 0);
if (memcmp(item->type, "av01", 4) && !isGrid) {
// probably exif or some other data
@@ -2043,6 +2066,10 @@
if (!item->id || !item->size) {
break;
}
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
avifBool isGrid = (memcmp(item->type, "grid", 4) == 0);
if (memcmp(item->type, "av01", 4) && !isGrid) {
// probably exif or some other data
@@ -2078,6 +2105,10 @@
if (!item->id || !item->size) {
break;
}
+ if (item->hasUnsupportedEssentialProperty) {
+ // An essential property isn't supported by libavif; ignore the item.
+ continue;
+ }
if (item->descForID != colorOBUItem->id) {
// Not a content description (metadata) for the colorOBU, skip it