com php-src: Fix #53156: imagerectangle problem with point ordering: ext/gd/libgd/gd.c ext/gd/tests/bug53156.phpt
| From: | Christoph Michael Becker | Date: | Mon, 20 Jul 2015 00:14:29 +0000 |
| Subject: | com php-src: Fix #53156: imagerectangle problem with point ordering: ext/gd/libgd/gd.c ext/gd/tests/bug53156.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88076@lists.php.net to get a copy of this message | ||
Commit: 72b73e24a00b9872214fbcc256ee38431d9c9d47
Author: Christoph M. Becker <cmbecker69@gmx.de> Mon, 20 Jul 2015 02:11:18 +0200
Parents: 90de2aeaac3de8f0744853ba197457c2241a4bdf
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=72b73e24a00b9872214fbcc256ee38431d9c9d47
Log:
Fix #53156: imagerectangle problem with point ordering
Contrary to imagefilledrectangle(), imagerectangle() has the documented
limitation that the given points have to be the upper left and the lower right
corner, respectively. However, libgd already caters to upper right / lower left
pairs, and not catering to the other two combinations seems to be an oversight.
Bugs:
https://bugs.php.net/53156
Changed paths:
M ext/gd/libgd/gd.c
A ext/gd/tests/bug53156.phpt
Diff:
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index c75c985..f03fd02 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -2044,7 +2044,9 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int
color)
t=y1;
y1 = y2;
y2 = t;
-
+ }
+
+ if (x2 < x1) {
t = x1;
x1 = x2;
x2 = t;
diff --git a/ext/gd/tests/bug53156.phpt b/ext/gd/tests/bug53156.phpt
new file mode 100644
index 0000000..a269369
--- /dev/null
+++ b/ext/gd/tests/bug53156.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Bug #53156 (imagerectangle problem with point ordering)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+function draw_and_check_pixel($x, $y)
+{
+ global $img, $black, $red;
+
+ echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';
+ imagesetpixel($img, $x, $y, $red);
+}
+
+function draw_and_check_rectangle($x1, $y1, $x2, $y2)
+{
+ global $img, $black;
+
+ echo 'Rectangle: ';
+ imagerectangle($img, $x1, $y1, $x2, $y2, $black);
+ draw_and_check_pixel(($x1 + $x2) / 2, $y1);
+ draw_and_check_pixel($x1, ($y1 + $y2) / 2);
+ draw_and_check_pixel(($x1 + $x2) / 2, $y2);
+ draw_and_check_pixel($x2, ($y1 + $y2) / 2);
+ echo PHP_EOL;
+}
+
+$img = imagecreate(110, 210);
+$bgnd = imagecolorallocate($img, 255, 255, 255);
+$black = imagecolorallocate($img, 0, 0, 0);
+$red = imagecolorallocate($img, 255, 0, 0);
+
+draw_and_check_rectangle(10, 10, 50, 50);
+draw_and_check_rectangle(50, 60, 10, 100);
+draw_and_check_rectangle(50, 150, 10, 110);
+draw_and_check_rectangle(10, 200, 50, 160);
+imagesetthickness($img, 4);
+draw_and_check_rectangle(60, 10, 100, 50);
+draw_and_check_rectangle(100, 60, 60, 100);
+draw_and_check_rectangle(100, 150, 60, 110);
+draw_and_check_rectangle(60, 200, 100, 160);
+
+imagepng($img, __DIR__ . '/bug53156.png');
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/bug53156.png');
+?>
+--EXPECT--
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++