Skip to content

Commit

Permalink
Check imageSizeLimit earlier in avifjpeg.c (#2031)
Browse files Browse the repository at this point in the history
Avoid libjpeg-turbo allocating too many bytes by checking
dimensions before calling jpeg_start_decompress().
  • Loading branch information
y-guyon authored Feb 22, 2024
1 parent bebf72a commit 22713e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,12 @@ static avifBool avifJPEGReadInternal(FILE * f,
jpeg_stdio_src(&cinfo, f);
jpeg_read_header(&cinfo, TRUE);

jpeg_calc_output_dimensions(&cinfo);
if (cinfo.output_width > imageSizeLimit / cinfo.output_height) {
fprintf(stderr, "Too big JPEG dimensions (%u x %u > %u px): %s\n", cinfo.output_width, cinfo.output_height, imageSizeLimit, inputFilename);
goto cleanup;
}

if (!ignoreColorProfile) {
uint8_t * iccDataTmp;
unsigned int iccDataLen;
Expand Down Expand Up @@ -931,10 +937,6 @@ static avifBool avifJPEGReadInternal(FILE * f,

avif->width = cinfo.output_width;
avif->height = cinfo.output_height;
if ((uint32_t)avif->width > imageSizeLimit / (uint32_t)avif->height) {
fprintf(stderr, "Too big JPEG dimensions (%d x %d > %u px): %s\n", avif->width, avif->height, imageSizeLimit, inputFilename);
goto cleanup;
}
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
const avifBool useYCgCoR = (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE ||
avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
Expand Down

0 comments on commit 22713e3

Please sign in to comment.