Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the num_channels field of the 'pixi' box #642

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ static avifResult avifDecoderItemMaxExtent(const avifDecoderItem * item, avifExt
return AVIF_RESULT_OK;
}

static avifResult avifDecoderItemValidateAV1(const avifDecoderItem * item, avifDiagnostics * diag, const avifStrictFlags strictFlags)
static avifResult avifDecoderItemValidateAV1(const avifDecoderItem * item, avifDiagnostics * diag, avifStrictFlags strictFlags, avifBool alpha)
{
const avifProperty * av1CProp = avifPropertyArrayFind(&item->properties, "av1C");
if (!av1CProp) {
Expand All @@ -755,6 +755,28 @@ static avifResult avifDecoderItemValidateAV1(const avifDecoderItem * item, avifD
}

if (pixiProp) {
const int av1CPlaneCount = av1CProp->u.av1C.monochrome ? 1 : 3;
if (alpha) {
// Older versions of libaom could not encode monochrome images, so some alpha
// auxilliary images may have been encoded in the YUV 4:2:0 format rather than
// monochrome. Do not compare with av1CPlaneCount in this case.
if (pixiProp->u.pixi.planeCount != 1) {
avifDiagnosticsPrintf(diag,
"Item ID %u number of channels specified by pixi property [%u] is not 1",
item->id,
pixiProp->u.pixi.planeCount);
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
} else {
if (pixiProp->u.pixi.planeCount != av1CPlaneCount) {
avifDiagnosticsPrintf(diag,
"Item ID %u number of channels specified by pixi property [%u] does not match av1C property number of channels [%d]",
item->id,
pixiProp->u.pixi.planeCount,
av1CPlaneCount);
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
}
const uint32_t av1CDepth = avifCodecConfigurationBoxGetDepth(&av1CProp->u.av1C);
for (uint8_t i = 0; i < pixiProp->u.pixi.planeCount; ++i) {
if (pixiProp->u.pixi.planeDepths[i] != av1CDepth) {
Expand Down Expand Up @@ -3062,12 +3084,12 @@ avifResult avifDecoderReset(avifDecoder * decoder)
decoder->alphaPresent = (alphaItem != NULL);
decoder->image->alphaPremultiplied = decoder->alphaPresent && (colorItem->premByID == alphaItem->id);

avifResult colorItemValidationResult = avifDecoderItemValidateAV1(colorItem, &decoder->diag, decoder->strictFlags);
avifResult colorItemValidationResult = avifDecoderItemValidateAV1(colorItem, &decoder->diag, decoder->strictFlags, AVIF_FALSE);
if (colorItemValidationResult != AVIF_RESULT_OK) {
return colorItemValidationResult;
}
if (alphaItem) {
avifResult alphaItemValidationResult = avifDecoderItemValidateAV1(alphaItem, &decoder->diag, decoder->strictFlags);
avifResult alphaItemValidationResult = avifDecoderItemValidateAV1(alphaItem, &decoder->diag, decoder->strictFlags, AVIF_TRUE);
if (alphaItemValidationResult != AVIF_RESULT_OK) {
return alphaItemValidationResult;
}
Expand Down