Bug #55005 [Opn]: imagepolygon, imagefilledpolygon num_points requirement

From: Date: Mon, 22 Jun 2015 22:03:06 +0000
Subject: Bug #55005 [Opn]: imagepolygon, imagefilledpolygon num_points requirement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193773@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55005&edit=1

 ID:                 55005
 User updated by:    lbayuk at users dot sourceforge dot net
 Reported by:        lbayuk at users dot sourceforge dot net
 Summary:            imagepolygon, imagefilledpolygon num_points
                     requirement
 Status:             Open
 Type:               Bug
 Package:            GD related
 Operating System:   n/a
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Verified still there in PHP-5.6.10


Previous Comments:
------------------------------------------------------------------------
[2011-06-06 23:26:43] lbayuk at users dot sourceforge dot net

Description:
------------
The gd extension function imagepolygon() requires at least 3 points.  While this restriction is
documented for imagefilledpolygon(), it is not documented for imagepolygon(). Since both are
implemented with the same function php_imagepolygon() and contain the same check, the documentation
for imagepolygon() should be updated to match imagefilledpolygon() in requiring at least 3 points.

However, this is not just a documentation problem. The implementation does not actually check for
num_points >= 3 as the documentation for imagefilledpolygon says. It checks that the points array
size is at least 6 (3 points, 2 values each). So you can plot a 2-point or even 1-point filled or
unfilled polygon, if you use an array with 3 or more points in it but specify num_points=2 or 1. 
This is very strange, not working as documented, and surely not as intended.

But there's more. As far as I can tell, libgd (bundled or stand-alone) doesn't actually
have a 3-point minimum restriction to gdImagePolygon() or gdImageFilledPolygon(), although it does
seem to be documented. See the sample code below, which plots 2-point filled and unfilled polygons
by using the above trick. It also works with num_points=1.  If true, the PHP check for 3 or more
points is not needed at all. 

Test script:
---------------
<?php
# Plot illegal 2-point polygon and filled polygon using over-sized array.
$g = imagecreate(300, 300);
$bgnd = imagecolorallocate($g, 255, 255, 255);
$fgnd = imagecolorallocate($g, 0, 0, 0);
imagefilledpolygon($g, array(100,10, 100,100, 180,100), 2, $fgnd);
imagepolygon($g, array(200,10, 200,100, 280,100), 2, $fgnd);
imagepng($g);


Expected result:
----------------
An error, since num_points=2 is not valid per documentation of ImageFilledPolygon.

Actual result:
--------------
A PNG image with 2 lines (2-point polygons).


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=55005&edit=1


Thread (8 messages)

« previous php.bugs (#193773) next »