Skip to content

Commit

Permalink
Check that >0 pixi planes have the same depth (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-guyon authored Mar 15, 2024
1 parent c783651 commit 6094ac0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,12 +2222,19 @@ static avifBool avifParsePixelInformationProperty(avifProperty * prop, const uin

avifPixelInformationProperty * pixi = &prop->u.pixi;
AVIF_CHECK(avifROStreamRead(&s, &pixi->planeCount, 1)); // unsigned int (8) num_channels;
if (pixi->planeCount > MAX_PIXI_PLANE_DEPTHS) {
if (pixi->planeCount < 1 || pixi->planeCount > MAX_PIXI_PLANE_DEPTHS) {
avifDiagnosticsPrintf(diag, "Box[pixi] contains unsupported plane count [%u]", pixi->planeCount);
return AVIF_FALSE;
}
for (uint8_t i = 0; i < pixi->planeCount; ++i) {
AVIF_CHECK(avifROStreamRead(&s, &pixi->planeDepths[i], 1)); // unsigned int (8) bits_per_channel;
if (pixi->planeDepths[i] != pixi->planeDepths[0]) {
avifDiagnosticsPrintf(diag,
"Box[pixi] contains unsupported mismatched plane depths [%u != %u]",
pixi->planeDepths[i],
pixi->planeDepths[0]);
return AVIF_FALSE;
}
}
return AVIF_TRUE;
}
Expand Down Expand Up @@ -4609,12 +4616,7 @@ static avifResult avifDecoderFindGainMapItem(const avifDecoder * decoder,

const avifProperty * pixiProp = avifPropertyArrayFind(&toneMappedImageItemTmp->properties, "pixi");
if (pixiProp) {
if (pixiProp->u.pixi.planeCount == 0) {
avifDiagnosticsPrintf(data->diag, "Box[pixi] of tmap item contains unsupported plane count [%u]", pixiProp->u.pixi.planeCount);
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
gainMap->altPlaneCount = pixiProp->u.pixi.planeCount;
// Assume all planes have the same depth.
gainMap->altDepth = pixiProp->u.pixi.planeDepths[0];
}
}
Expand Down

0 comments on commit 6094ac0

Please sign in to comment.