Skip to content

Commit 26f9893

Browse files
committed
Fix GH-20070: Return type violation in imagefilter when an invalid filter is provided
Closes GH-20071
1 parent f9aeb9e commit 26f9893

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug GH-19974 (fpm_status_export_to_zval segfault for parallel
1212
execution). (Jakub Zelenka, txuna)
1313

14+
- GD:
15+
. Fixed bug GH-20070 (Return type violation in imagefilter when an invalid
16+
filter is provided). (Girgias)
17+
1418
- Opcache:
1519
. Fixed bug GH-20081 (access to uninitialized vars in preload_load()).
1620
(Arnaud)

ext/gd/gd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,9 +3404,11 @@ PHP_FUNCTION(imagefilter)
34043404
RETURN_THROWS();
34053405
}
34063406

3407-
if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
3408-
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
3407+
if (UNEXPECTED(filtertype < 0 || filtertype > IMAGE_FILTER_MAX)) {
3408+
zend_argument_value_error(2, "must be one of the IMG_FILTER_* filter constants");
3409+
RETURN_THROWS();
34093410
}
3411+
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
34103412
}
34113413
/* }}} */
34123414

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-20070: Testing wrong parameter passing in imagefilter() of GD library
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$image = imagecreatetruecolor(1, 1);
8+
9+
try {
10+
var_dump(imagefilter($image, -1));
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
ValueError: imagefilter(): Argument #2 ($filter) must be one of the IMG_FILTER_* filter constants

0 commit comments

Comments
 (0)