diff --git a/NEWS b/NEWS index 8771d8eae544..b62b94099e6e 100644 --- a/NEWS +++ b/NEWS @@ -202,6 +202,7 @@ PHP NEWS (DanielEScherzer, cmb) . Fixed undefined behavior with GIFs with problematic LZW compression data. (DanielEScherzer, vapier) + . Fixed the return value of imagewebp() for palette images. (arshidkv12) - Intl: . Fixed IntlDateFormatter::parse(), localtime() and parseToCalendar() diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 92001c4f9967..c789600c37e9 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -2009,7 +2009,10 @@ PHP_FUNCTION(imagewebp) RETURN_THROWS(); } - gdImageWebpCtx(im, ctx, (int) quality); + if (!gdImageWebpCtxEx(im, ctx, (int) quality)) { + ctx->gd_free(ctx); + RETURN_FALSE; + } ctx->gd_free(ctx); diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h index 672ddf94837c..83dfe796c7ea 100644 --- a/ext/gd/libgd/gd.h +++ b/ext/gd/libgd/gd.h @@ -48,6 +48,7 @@ extern "C" { /* va_list needed in gdErrorMethod */ #include +#include /* The maximum number of palette entries in palette-based images. In the wonderful new world of gd 2.0, you can of course have @@ -633,6 +634,7 @@ void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality); #define gdWebpLossless 101 void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality); +bool gdImageWebpCtxEx (gdImagePtr im, gdIOCtx * outfile, int quality); /* Best to free this memory with gdFree(), not free() */ void *gdImageJpegPtr(gdImagePtr im, int *size, int quality); diff --git a/ext/gd/libgd/gd_webp.c b/ext/gd/libgd/gd_webp.c index 6277e09710f9..423be70d4997 100644 --- a/ext/gd/libgd/gd_webp.c +++ b/ext/gd/libgd/gd_webp.c @@ -101,7 +101,11 @@ gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile) return im; } -void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) +void gdImageWebpCtx(gdImagePtr im, gdIOCtx *outfile, int quality){ + gdImageWebpCtxEx(im, outfile, quality); +} + +bool gdImageWebpCtxEx (gdImagePtr im, gdIOCtx * outfile, int quality) { uint8_t *argb; int x, y; @@ -110,12 +114,12 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) size_t out_size; if (im == NULL) { - return; + return false; } if (!gdImageTrueColor(im)) { gd_error("Palette image not supported by webp"); - return; + return false; } if (quality == -1) { @@ -123,16 +127,16 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) } if (overflow2(gdImageSX(im), 4)) { - return; + return false; } if (overflow2(gdImageSX(im) * 4, gdImageSY(im))) { - return; + return false; } argb = (uint8_t *)gdMalloc(gdImageSX(im) * 4 * gdImageSY(im)); if (!argb) { - return; + return false; } p = argb; for (y = 0; y < gdImageSY(im); y++) { @@ -165,9 +169,12 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) } gdPutBuf(out, out_size, outfile); free(out); + gdFree(argb); + return true; freeargb: gdFree(argb); + return false; } void gdImageWebpEx (gdImagePtr im, FILE * outFile, int quality) diff --git a/ext/gd/tests/gh24457.phpt b/ext/gd/tests/gh24457.phpt new file mode 100644 index 000000000000..8575d350481e --- /dev/null +++ b/ext/gd/tests/gh24457.phpt @@ -0,0 +1,29 @@ +--TEST-- +imagewebp() with a palette image +--EXTENSIONS-- +gd +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +Warning: imagewebp(): Palette image not supported by webp in %s on line %d +bool(false) + +Warning: imagewebp(): gd-webp encoding failed in %s on line %d +bool(false) \ No newline at end of file