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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ PHP NEWS

- GD:
. Fixed GH-19955 (imagefttext() memory leak). (David Carlier)
. Fixed GH-20070 (ext/gd: Return type violation in imagefilter when an
invalid filter is provided). (Girgias)

- MySQLnd:
. Fixed bug #67563 (mysqli compiled with mysqlnd does not take ipv6 adress
Expand Down
6 changes: 4 additions & 2 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3404,9 +3404,11 @@ PHP_FUNCTION(imagefilter)
RETURN_THROWS();
}

if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (UNEXPECTED(filtertype < 0 || filtertype > IMAGE_FILTER_MAX)) {
zend_argument_value_error(2, "must be one of the IMG_FILTER_* filter constants");
RETURN_THROWS();
}
filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */

Expand Down
16 changes: 16 additions & 0 deletions ext/gd/tests/imagefilter_invalid_filter_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-20070: Testing wrong parameter passing in imagefilter() of GD library
--EXTENSIONS--
gd
--FILE--
<?php
$image = imagecreatetruecolor(1, 1);

try {
var_dump(imagefilter($image, -1));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: imagefilter(): Argument #2 ($filter) must be one of the IMG_FILTER_* filter constants
Comment on lines +9 to +16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks a lot for the fix! I just have two suggestions:

  1. I think we can remove the var_dump as it's not necessary.
  2. I believe the current test only checks that the value isn't less than the minimum allowed filter, but it doesn't test that it isn't greater than the maximum allowed filter. The fix should address that, so it might be worth adding a test for that case as well.

Thanks again for the fix!

Suggested change
try {
var_dump(imagefilter($image, -1));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: imagefilter(): Argument #2 ($filter) must be one of the IMG_FILTER_* filter constants
try {
imagefilter($image, -1);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
imagefilter($image, 999);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
ValueError: imagefilter(): Argument #2 ($filter) must be one of the IMG_FILTER_* filter constants
ValueError: imagefilter(): Argument #2 ($filter) must be one of the IMG_FILTER_* filter constants

Loading