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

Add diagnostic messages if imageSizeLimit exceeded #732

Merged
Merged
Show file tree
Hide file tree
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
18 changes: 15 additions & 3 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,14 @@ static avifBool avifParseImageGridBox(avifImageGrid * grid, const uint8_t * raw,
CHECK(avifROStreamReadU32(&s, &grid->outputWidth)); // unsigned int(FieldLength) output_width;
CHECK(avifROStreamReadU32(&s, &grid->outputHeight)); // unsigned int(FieldLength) output_height;
}
if ((grid->outputWidth == 0) || (grid->outputHeight == 0) || (grid->outputWidth > (imageSizeLimit / grid->outputHeight))) {
if ((grid->outputWidth == 0) || (grid->outputHeight == 0)) {
avifDiagnosticsPrintf(diag, "Grid box contains illegal dimensions: [%u x %u]", grid->outputWidth, grid->outputHeight);
return AVIF_FALSE;
}
if (grid->outputWidth > (imageSizeLimit / grid->outputHeight)) {
avifDiagnosticsPrintf(diag, "Grid box dimensions are too large: [%u x %u]", grid->outputWidth, grid->outputHeight);
return AVIF_FALSE;
}
return avifROStreamRemainingBytes(&s) == 0;
}

Expand Down Expand Up @@ -2365,10 +2369,14 @@ static avifBool avifParseTrackHeaderBox(avifTrack * track, const uint8_t * raw,
track->width = width >> 16;
track->height = height >> 16;

if ((track->width == 0) || (track->height == 0) || (track->width > (imageSizeLimit / track->height))) {
if ((track->width == 0) || (track->height == 0)) {
avifDiagnosticsPrintf(diag, "Track ID [%u] has an invalid size [%ux%u]", track->id, track->width, track->height);
return AVIF_FALSE;
}
if (track->width > (imageSizeLimit / track->height)) {
avifDiagnosticsPrintf(diag, "Track ID [%u] size is too large [%ux%u]", track->id, track->width, track->height);
return AVIF_FALSE;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joe: I was planning to add the AVIF_RESULT_IMAGE_TOO_LARGE error code as we previously discussed. But I found that it would take a lot of plumbing (changing three or four functions) to surface the new error code from here. (The grid and item sizes are easy to handle.) In the end I decided to just reply on diagnostic messages and not add a new error code.


// TODO: support scaling based on width/height track header info?

Expand Down Expand Up @@ -3079,10 +3087,14 @@ avifResult avifDecoderParse(avifDecoder * decoder)
item->width = ispeProp->u.ispe.width;
item->height = ispeProp->u.ispe.height;

if ((item->width == 0) || (item->height == 0) || (item->width > (decoder->imageSizeLimit / item->height))) {
if ((item->width == 0) || (item->height == 0)) {
avifDiagnosticsPrintf(data->diag, "Item ID [%u] has an invalid size [%ux%u]", item->id, item->width, item->height);
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
if (item->width > (decoder->imageSizeLimit / item->height)) {
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 {
avifDiagnosticsPrintf(data->diag, "Item ID [%u] is missing a mandatory ispe property", item->id);
return AVIF_RESULT_BMFF_PARSE_FAILED;
Expand Down
6 changes: 5 additions & 1 deletion src/scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ avifBool avifImageScale(avifImage * image, uint32_t dstWidth, uint32_t dstHeight
return AVIF_TRUE;
}

if ((dstWidth == 0) || (dstHeight == 0) || (dstWidth > (imageSizeLimit / dstHeight))) {
if ((dstWidth == 0) || (dstHeight == 0)) {
avifDiagnosticsPrintf(diag, "avifImageScale requested invalid dst dimensions [%ux%u]", dstWidth, dstHeight);
return AVIF_FALSE;
}
if (dstWidth > (imageSizeLimit / dstHeight)) {
avifDiagnosticsPrintf(diag, "avifImageScale requested dst dimensions that are too large [%ux%u]", dstWidth, dstHeight);
return AVIF_FALSE;
}

uint8_t * srcYUVPlanes[AVIF_PLANE_COUNT_YUV];
uint32_t srcYUVRowBytes[AVIF_PLANE_COUNT_YUV];
Expand Down