Skip to content

Commit b456ae8

Browse files
dryabovdevnexen
authored andcommitted
Restore Warning instead of Fatal Error in gd_webp.c
According to the docs (https://www.php.net/manual/en/function.imagecreatefromwebp.php and https://www.php.net/manual/en/function.imagewebp.php), `false` should be returned on errors (similar to other functions of the `gd` extension), but actually all errors result in a `Fatal Error`. It doesn't look normal when trying to read an empty file or a file in the wrong format causes the program to stop. The problem seems to be related to a mega-patch that replaced `zend_error` with `zend_error_noreturn` almost everywhere. My patch fixes this behavior by switching from `zend_error_noerror` to `gd_error` (i.e. to `E_WARNING` level). All necessary memory cleanup is already in the code (as it was before the "zend_error_noreturn" patch). Close GH-13774
1 parent 09957ab commit b456ae8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PHP NEWS
1616

1717
- Gd:
1818
. ext/gd/tests/gh10614.phpt: skip if no PNG support. (orlitzky)
19+
. restored warning instead of fata error. (dryabov)
1920

2021
- LibXML:
2122
. Fixed bug GH-14563 (Build failure with libxml2 v2.13.0). (nielsdos)

ext/gd/libgd/gd_webp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string.h>
44
#include <stdlib.h>
55
#include "gd.h"
6+
#include "gd_errors.h"
67
#include "gdhelpers.h"
78

89
#ifdef HAVE_LIBWEBP
@@ -56,7 +57,7 @@ gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile)
5657
if (filedata) {
5758
gdFree(filedata);
5859
}
59-
zend_error(E_ERROR, "WebP decode: realloc failed");
60+
gd_error("WebP decode: realloc failed");
6061
return NULL;
6162
}
6263

@@ -67,7 +68,7 @@ gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile)
6768
} while (n>0 && n!=EOF);
6869

6970
if (WebPGetInfo(filedata,size, &width, &height) == 0) {
70-
zend_error(E_ERROR, "gd-webp cannot get webp info");
71+
gd_error("gd-webp cannot get webp info");
7172
gdFree(filedata);
7273
return NULL;
7374
}
@@ -79,7 +80,7 @@ gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile)
7980
}
8081
argb = WebPDecodeARGB(filedata, size, &width, &height);
8182
if (!argb) {
82-
zend_error(E_ERROR, "gd-webp cannot allocate temporary buffer");
83+
gd_error("gd-webp cannot allocate temporary buffer");
8384
gdFree(filedata);
8485
gdImageDestroy(im);
8586
return NULL;
@@ -113,7 +114,7 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
113114
}
114115

115116
if (!gdImageTrueColor(im)) {
116-
zend_error(E_ERROR, "Palette image not supported by webp");
117+
gd_error("Palette image not supported by webp");
117118
return;
118119
}
119120

@@ -159,7 +160,7 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
159160
}
160161

161162
if (out_size == 0) {
162-
zend_error(E_ERROR, "gd-webp encoding failed");
163+
gd_error("gd-webp encoding failed");
163164
goto freeargb;
164165
}
165166
gdPutBuf(out, out_size, outfile);

0 commit comments

Comments
 (0)