php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch imagepolygon-numpoints for GD related Bug #55005

Patch version 2015-07-13 18:19 UTC

Return to Bug #55005 | Download this patch
Patch Revisions:

Developer: cmb@php.net

 ext/gd/gd.c                                   |  8 ++------
 ext/gd/tests/bug55005.phpt                    | 20 ++++++++++++++++++++
 ext/gd/tests/imagefilledpolygon_negative.phpt | 15 ---------------
 ext/gd/tests/imagepolygon_negative.phpt       | 15 ---------------
 4 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index abd7b75..12bdbf0 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -3346,12 +3346,8 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
 	col = COL;
 
 	nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
-	if (nelem < 6) {
-		php_error_docref(NULL, E_WARNING, "You must have at least 3 points in your array");
-		RETURN_FALSE;
-	}
-	if (npoints <= 0) {
-		php_error_docref(NULL, E_WARNING, "You must give a positive number of points");
+	if (npoints < 3) {
+		php_error_docref(NULL, E_WARNING, "You must have at least 3 points");
 		RETURN_FALSE;
 	}
 	if (nelem < npoints * 2) {
diff --git a/ext/gd/tests/bug55005.phpt b/ext/gd/tests/bug55005.phpt
new file mode 100644
index 0000000..113988f
--- /dev/null
+++ b/ext/gd/tests/bug55005.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #55005 (imagepolygon, imagefilledpolygon num_points requirement)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$g = imagecreate(300, 300);
+$bgnd = imagecolorallocate($g, 255, 255, 255);
+$fgnd = imagecolorallocate($g, 0, 0, 0);
+var_dump(imagefilledpolygon($g, array(100,10, 100,100, 180,100), 2, $fgnd));
+var_dump(imagepolygon($g, array(200,10, 200,100, 280,100), 2, $fgnd));
+?>
+--EXPECTF--
+Warning: imagefilledpolygon(): You must have at least 3 points in %s on line %d
+bool(false)
+
+Warning: imagepolygon(): You must have at least 3 points in %s on line %d
+bool(false)
diff --git a/ext/gd/tests/imagefilledpolygon_negative.phpt b/ext/gd/tests/imagefilledpolygon_negative.phpt
deleted file mode 100644
index ced8530..0000000
--- a/ext/gd/tests/imagefilledpolygon_negative.phpt
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-imagefilledpolygon() with a negative num of points
---SKIPIF--
-<?php 
-	if (!function_exists('imagefilledpolygon')) die('skip imagefilledpolygon() not available'); 
-?>
---FILE--
-<?php
-$im = imagecreate(100, 100);
-$black = imagecolorallocate($im, 0, 0, 0);
-if (imagefilledpolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
-imagedestroy($im);
-?>
---EXPECTF--
-Warning: imagefilledpolygon(): You must give a positive number of points in %s on line %d
diff --git a/ext/gd/tests/imagepolygon_negative.phpt b/ext/gd/tests/imagepolygon_negative.phpt
deleted file mode 100644
index bb9010c..0000000
--- a/ext/gd/tests/imagepolygon_negative.phpt
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-imagepolygon() with a negative num of points
---SKIPIF--
-<?php 
-	if (!function_exists('imagepolygon')) die('skip imagepolygon() not available'); 
-?>
---FILE--
-<?php
-$im = imagecreate(100, 100);
-$black = imagecolorallocate($im, 0, 0, 0);
-if (imagepolygon($im, array(0, 0, 0, 0, 0, 0), -1, $black)) echo "should be false";
-imagedestroy($im);
-?>
---EXPECTF--
-Warning: imagepolygon(): You must give a positive number of points in %s on line %d
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC