Skip to content

Commit 05176ad

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16427: Unchecked libavif return values
2 parents 77f7708 + b817a4f commit 05176ad

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PHP NEWS
2929
- GD:
3030
. Fixed bug GH-16334 (imageaffine overflow on matrix elements).
3131
(David Carlier)
32+
. Fixed bug GH-16427 (Unchecked libavif return values). (cmb)
3233

3334
- GMP:
3435
. Fixed floating point exception bug with gmp_pow when using

ext/gd/libgd/gd_avif.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,13 @@ gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
393393
// (While AVIF image pixel depth can be 8, 10, or 12 bits, GD truecolor images are 8-bit.)
394394
avifRGBImageSetDefaults(&rgb, decoder->image);
395395
rgb.depth = 8;
396+
#if AVIF_VERSION >= 1000000
397+
result = avifRGBImageAllocatePixels(&rgb);
398+
if (isAvifError(result, "Allocating RGB pixels failed"))
399+
goto cleanup;
400+
#else
396401
avifRGBImageAllocatePixels(&rgb);
402+
#endif
397403

398404
result = avifImageYUVToRGB(decoder->image, &rgb);
399405
if (isAvifError(result, "Conversion from YUV to RGB failed"))
@@ -522,14 +528,25 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
522528
// Note that MATRIX_COEFFICIENTS_IDENTITY enables lossless conversion from RGB to YUV.
523529

524530
avifImage *avifIm = avifImageCreate(gdImageSX(im), gdImageSY(im), 8, subsampling);
525-
531+
#if AVIF_VERSION >= 1000000
532+
if (avifIm == NULL) {
533+
gd_error("avif error - Creating image failed\n");
534+
goto cleanup;
535+
}
536+
#endif
526537
avifIm->colorPrimaries = AVIF_COLOR_PRIMARIES_BT709;
527538
avifIm->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB;
528539
avifIm->matrixCoefficients = lossless ? AVIF_MATRIX_COEFFICIENTS_IDENTITY : AVIF_MATRIX_COEFFICIENTS_BT709;
529540

530541
avifRGBImageSetDefaults(&rgb, avifIm);
531542
// this allocates memory, and sets rgb.rowBytes and rgb.pixels.
543+
#if AVIF_VERSION >= 1000000
544+
result = avifRGBImageAllocatePixels(&rgb);
545+
if (isAvifError(result, "Allocating RGB pixels failed"))
546+
goto cleanup;
547+
#else
532548
avifRGBImageAllocatePixels(&rgb);
549+
#endif
533550

534551
// Parse RGB data from the GD image, and copy it into the AVIF RGB image.
535552
// 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)
555572
// Encode the image in AVIF format.
556573

557574
encoder = avifEncoderCreate();
575+
#if AVIF_VERSION >= 1000000
576+
if (encoder == NULL) {
577+
gd_error("avif error - Creating encoder failed\n");
578+
goto cleanup;
579+
}
580+
#endif
558581
int quantizerQuality = quality == QUALITY_DEFAULT ?
559582
QUANTIZER_DEFAULT : quality2Quantizer(quality);
560583

0 commit comments

Comments
 (0)