diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 5b2c34672f3b0..df741ef255d4a 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3605,7 +3605,7 @@ PHP_FUNCTION(imagefilter) zval *tmp; typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS); - zend_long filtertype; + zend_long filtertype = 0; image_filter filters[] = { php_image_filter_negate , @@ -3623,9 +3623,9 @@ PHP_FUNCTION(imagefilter) php_image_filter_scatter }; - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) { - WRONG_PARAM_COUNT; - } else if (zend_parse_parameters(2, "Ol", &tmp, gd_image_ce, &filtertype) == FAILURE) { + /* We need to do some initial ZPP parsing to be able to extract the filter value */ + if (zend_parse_parameters(MIN(2, ZEND_NUM_ARGS()), "Ol*", &tmp, gd_image_ce, &filtertype) == FAILURE) { + RETURN_THROWS(); } diff --git a/ext/gd/tests/imagefilter_error1.phpt b/ext/gd/tests/imagefilter_error1.phpt index 6e2ccabb874a8..cc9904e320dac 100644 --- a/ext/gd/tests/imagefilter_error1.phpt +++ b/ext/gd/tests/imagefilter_error1.phpt @@ -14,6 +14,12 @@ try { } catch (TypeError $e) { echo $e->getMessage(), "\n"; } +try { + var_dump(imagefilter(20, 1)); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} ?> --EXPECT-- -Wrong parameter count for imagefilter() +imagefilter() expects at least 2 arguments, 1 given +imagefilter(): Argument #1 ($image) must be of type GdImage, int given