Skip to content

Commit c1d0c61

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-20070: Return type violation in imagefilter when an invalid filter is provided
2 parents 053d72e + e7aea3d commit c1d0c61

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ext/gd/gd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,9 +3629,11 @@ PHP_FUNCTION(imagefilter)
36293629
RETURN_THROWS();
36303630
}
36313631

3632-
if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
3633-
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
3632+
if (UNEXPECTED(filtertype < 0 || filtertype > IMAGE_FILTER_MAX)) {
3633+
zend_argument_value_error(2, "must be one of the IMG_FILTER_* filter constants");
3634+
RETURN_THROWS();
36343635
}
3636+
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
36353637
}
36363638
/* }}} */
36373639

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)