diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 21fb90c3b4d1..27a4284fb844 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -2871,7 +2871,12 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS)); if (npoints < 3) { - zend_argument_value_error(3, "must be greater than or equal to 3"); + if (COL_IS_NULL) { + /* The count comes from the array, argument #3 is the color */ + zend_argument_value_error(2, "must have at least 3 points"); + } else { + zend_argument_value_error(3, "must be greater than or equal to 3"); + } RETURN_THROWS(); } diff --git a/ext/gd/tests/imagepolygon_too_few_points_argument.phpt b/ext/gd/tests/imagepolygon_too_few_points_argument.phpt new file mode 100644 index 000000000000..a3ccb3d279d6 --- /dev/null +++ b/ext/gd/tests/imagepolygon_too_few_points_argument.phpt @@ -0,0 +1,27 @@ +--TEST-- +imagepolygon(), imageopenpolygon(), imagefilledpolygon(): too few points blames the points array +--EXTENSIONS-- +gd +--FILE-- +getMessage(), "\n"; + } + try { + @$f($im, [1, 1, 2, 2], 2, 0xffffff); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +ValueError: imagepolygon(): Argument #2 ($points) must have at least 3 points +ValueError: imagepolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3 +ValueError: imageopenpolygon(): Argument #2 ($points) must have at least 3 points +ValueError: imageopenpolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3 +ValueError: imagefilledpolygon(): Argument #2 ($points) must have at least 3 points +ValueError: imagefilledpolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3