[php-src] master: Merge branch 'PHP-8.6'
| From: | David Carlier | Date: | Wed, 11 Nov 2026 06:43:04 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143566@lists.php.net to get a copy of this message | ||
Author: David Carlier (devnexen)
Date: 2026-11-11T06:41:49Z
Commit: https://github.com/php/php-src/commit/6d57acf7823244be00ca097aec3809d744958eaf
Raw diff: https://github.com/php/php-src/commit/6d57acf7823244be00ca097aec3809d744958eaf.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
ext/gd: blame the points array when a polygon has too few points
Changed paths:
A ext/gd/tests/imagepolygon_too_few_points_argument.phpt
M ext/gd/gd.c
Diff:
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 0adbe21cfbdb..5bcf11846316 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -2921,7 +2921,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--
+<?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