diff --git a/ext/gd/gd.c b/ext/gd/gd.c index c81861ab80193..962041232c618 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3981,6 +3981,11 @@ PHP_FUNCTION(imagescale) im = php_gd_libgdimageptr_from_zval_p(IM); + if (tmp_h < 0 && tmp_w < 0) { + zend_value_error("Argument #2 ($width) and argument #3 ($height) cannot be both negative"); + RETURN_THROWS(); + } + if (tmp_h < 0 || tmp_w < 0) { /* preserve ratio */ long src_x, src_y; diff --git a/ext/gd/tests/gh17703.phpt b/ext/gd/tests/gh17703.phpt new file mode 100644 index 0000000000000..4677b6a501391 --- /dev/null +++ b/ext/gd/tests/gh17703.phpt @@ -0,0 +1,17 @@ +--TEST-- +GH-17703 both width and height value being negative triggers ValueError on width. +--EXTENSIONS-- +gd +--FILE-- +getMessage(); +} +?> +--EXPECT-- +Argument #2 ($width) and argument #3 ($height) cannot be both negative