From 72b73e24a00b9872214fbcc256ee38431d9c9d47 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Jul 2015 02:11:18 +0200 Subject: [PATCH 1/3] 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. --- ext/gd/libgd/gd.c | 4 ++- ext/gd/tests/bug53156.phpt | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 ext/gd/tests/bug53156.phpt diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index c75c985c4ef..f03fd0278a6 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 00000000000..a269369670b --- /dev/null +++ b/ext/gd/tests/bug53156.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #53156 (imagerectangle problem with point ordering) +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ +Rectangle: ++++ From 2ec86112932e57b3f28a6448b5175a4089810cea Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Jul 2015 03:05:22 +0200 Subject: [PATCH 2/3] revised bug53156.phpt --- ext/gd/tests/bug53156.phpt | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/ext/gd/tests/bug53156.phpt b/ext/gd/tests/bug53156.phpt index a269369670b..24db8024fe3 100644 --- a/ext/gd/tests/bug53156.phpt +++ b/ext/gd/tests/bug53156.phpt @@ -20,33 +20,31 @@ function draw_and_check_rectangle($x1, $y1, $x2, $y2) 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); + $x = ($x1 + $x2) / 2; + $y = ($y1 + $y2) / 2; + draw_and_check_pixel($x, $y1); + draw_and_check_pixel($x1, $y); + draw_and_check_pixel($x, $y2); + draw_and_check_pixel($x2, $y); 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); +$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); +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); +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-- - --EXPECT-- Rectangle: ++++ From e3a85074edd2f92ca167e0b5c6be5c4633198686 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 21 Jul 2015 01:17:51 +0200 Subject: [PATCH 3/3] updated NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 0cedae6791e..838ad968878 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS . Fixed bug #64878 (304 responses return Content-Type header). (cmb) - GD: + . Fixed bug #53156 (imagerectangle problem with point ordering). (cmb) . Fixed bug #66387 (Stack overflow with imagefilltoborder). (cmb) . Fixed bug #70102 (imagecreatefromwebm() shifts colors). (cmb) . Fixed bug #66590 (imagewebp() doesn't pad to even length). (cmb)