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

From: Date: Mon, 06 Jun 2011 21:26:43 +0000
Subject: Bug #55005 [NEW]: imagepolygon, imagefilledpolygon num_points requirement
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161219@lists.php.net to get a copy of this message
From:             
Operating system: n/a
PHP version:      5.3.6
Package:          GD related
Bug Type:         Bug
Bug description:imagepolygon, imagefilledpolygon num_points requirement

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 bug report at http://bugs.php.net/bug.php?id=55005&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=55005&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=55005&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=55005&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=55005&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=55005&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=55005&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=55005&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=55005&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=55005&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=55005&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=55005&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=55005&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=55005&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=55005&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=55005&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=55005&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=55005&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=55005&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=55005&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=55005&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=55005&r=mysqlcfg



Thread (8 messages)

« previous php.bugs (#161219) next »