Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-16427: Unchecked libavif return values
This commit is contained in:
Christoph M. Becker 2024-10-14 13:54:40 +02:00
commit 055b15f08c
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
2 changed files with 25 additions and 1 deletions

1
NEWS
View File

@ -33,6 +33,7 @@ PHP NEWS
- GD:
. Fixed bug GH-16334 (imageaffine overflow on matrix elements).
(David Carlier)
. Fixed bug GH-16427 (Unchecked libavif return values). (cmb)
- GMP:
. Fixed floating point exception bug with gmp_pow when using

View File

@ -393,7 +393,13 @@ gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
// (While AVIF image pixel depth can be 8, 10, or 12 bits, GD truecolor images are 8-bit.)
avifRGBImageSetDefaults(&rgb, decoder->image);
rgb.depth = 8;
#if AVIF_VERSION >= 1000000
result = avifRGBImageAllocatePixels(&rgb);
if (isAvifError(result, "Allocating RGB pixels failed"))
goto cleanup;
#else
avifRGBImageAllocatePixels(&rgb);
#endif
result = avifImageYUVToRGB(decoder->image, &rgb);
if (isAvifError(result, "Conversion from YUV to RGB failed"))
@ -522,14 +528,25 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
// Note that MATRIX_COEFFICIENTS_IDENTITY enables lossless conversion from RGB to YUV.
avifImage *avifIm = avifImageCreate(gdImageSX(im), gdImageSY(im), 8, subsampling);
#if AVIF_VERSION >= 1000000
if (avifIm == NULL) {
gd_error("avif error - Creating image failed\n");
goto cleanup;
}
#endif
avifIm->colorPrimaries = AVIF_COLOR_PRIMARIES_BT709;
avifIm->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB;
avifIm->matrixCoefficients = lossless ? AVIF_MATRIX_COEFFICIENTS_IDENTITY : AVIF_MATRIX_COEFFICIENTS_BT709;
avifRGBImageSetDefaults(&rgb, avifIm);
// this allocates memory, and sets rgb.rowBytes and rgb.pixels.
#if AVIF_VERSION >= 1000000
result = avifRGBImageAllocatePixels(&rgb);
if (isAvifError(result, "Allocating RGB pixels failed"))
goto cleanup;
#else
avifRGBImageAllocatePixels(&rgb);
#endif
// Parse RGB data from the GD image, and copy it into the AVIF RGB image.
// Convert 7-bit GD alpha channel values to 8-bit AVIF values.
@ -555,6 +572,12 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
// Encode the image in AVIF format.
encoder = avifEncoderCreate();
#if AVIF_VERSION >= 1000000
if (encoder == NULL) {
gd_error("avif error - Creating encoder failed\n");
goto cleanup;
}
#endif
int quantizerQuality = quality == QUALITY_DEFAULT ?
QUANTIZER_DEFAULT : quality2Quantizer(quality);