Skip to content
Closed
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
7 changes: 6 additions & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
27 changes: 27 additions & 0 deletions ext/gd/tests/imagepolygon_too_few_points_argument.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
imagepolygon(), imageopenpolygon(), imagefilledpolygon(): too few points blames the points array
--EXTENSIONS--
gd
--FILE--
<?php
$im = imagecreatetruecolor(20, 20);
foreach (['imagepolygon', 'imageopenpolygon', 'imagefilledpolygon'] as $f) {
try {
$f($im, [1, 1, 2, 2], 0xffffff);
} catch (Throwable $e) {
echo $e::class, ': ', $e->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
Loading