Skip to content

Commit 758aa7c

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: ext/gd: blame the points array when a polygon has too few points
2 parents 7a94204 + 764ab59 commit 758aa7c

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎ext/gd/gd.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,12 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
29212921

29222922
nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
29232923
if (npoints < 3) {
2924-
zend_argument_value_error(3, "must be greater than or equal to 3");
2924+
if (COL_IS_NULL) {
2925+
/* The count comes from the array, argument #3 is the color */
2926+
zend_argument_value_error(2, "must have at least 3 points");
2927+
} else {
2928+
zend_argument_value_error(3, "must be greater than or equal to 3");
2929+
}
29252930
RETURN_THROWS();
29262931
}
29272932

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
imagepolygon(), imageopenpolygon(), imagefilledpolygon(): too few points blames the points array
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreatetruecolor(20, 20);
8+
foreach (['imagepolygon', 'imageopenpolygon', 'imagefilledpolygon'] as $f) {
9+
try {
10+
$f($im, [1, 1, 2, 2], 0xffffff);
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
try {
15+
@$f($im, [1, 1, 2, 2], 2, 0xffffff);
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), "\n";
18+
}
19+
}
20+
?>
21+
--EXPECT--
22+
ValueError: imagepolygon(): Argument #2 ($points) must have at least 3 points
23+
ValueError: imagepolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3
24+
ValueError: imageopenpolygon(): Argument #2 ($points) must have at least 3 points
25+
ValueError: imageopenpolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3
26+
ValueError: imagefilledpolygon(): Argument #2 ($points) must have at least 3 points
27+
ValueError: imagefilledpolygon(): Argument #3 ($num_points_or_color) must be greater than or equal to 3

0 commit comments

Comments
 (0)