Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions ext/gd/libgd/gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern "C" {

/* va_list needed in gdErrorMethod */
#include <stdarg.h>
#include <stdbool.h>

/* The maximum number of palette entries in palette-based images.
In the wonderful new world of gd 2.0, you can of course have
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 13 additions & 6 deletions ext/gd/libgd/gd_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -110,29 +114,29 @@ 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) {
quality = 80;
}

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++) {
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions ext/gd/tests/gh24457.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
imagewebp() with a palette image
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!function_exists('imagewebp')) {
die('skip WebP support is not available');
}
?>
--FILE--
<?php
$im = imagecreate(4, 4);
var_dump(imagewebp($im, __DIR__ . '/imagewebp_palette.webp'));

$im = imagecreatetruecolor(16384, 1);
var_dump(imagewebp($im, __DIR__ . '/imagewebp_truecolor.webp'));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/imagewebp_palette.webp');
@unlink(__DIR__ . '/imagewebp_truecolor.webp');
?>
--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)
Loading