[php-src] PR #13774: Restore Warning instead of Fatal Error in gd_webp.c
| From: | dryabov | Date: | Thu, 21 Mar 2024 10:43:34 +0000 |
| Subject: | [php-src] PR #13774: Restore Warning instead of Fatal Error in gd_webp.c | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-25506@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/13774
Author: dryabov
According to the docs (see 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).
You can use the following code to test:
```php
<?php
$empty_webp = __DIR__ . '/empty.webp';
file_put_contents($empty_webp, '');
$im = imagecreatefromwebp($empty_webp);
```
**Current** result:
```
Fatal error: gd-webp cannot get webp info in ...
```
**Expected** result:
```
Warning: imagecreatefromwebp(): gd-webp cannot get webp info in ...
```