From 094decc3c0b62a72bacebaf85c6269049bf12885 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 13 Jul 2015 01:29:01 +0200 Subject: [PATCH] Fix #53154: Zero-height rectangle has whiskers To avoid drawing the corner pixels twice, gdImageRectangle() draws the vertical lines 2 points shorter than the actual side of the rectangle. However, this causes "whiskers" for rectangles with height 0. This patch fixes this issue and at the same time optimizes the algorithm by drawing only a single line for zero height and zero width rectangles. --- ext/gd/libgd/gd.c | 16 ++++++++++------ ext/gd/tests/bug53154.phpt | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 ext/gd/tests/bug53154.phpt diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index d73f0943af..c75c985c4e 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -2095,12 +2095,16 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color) return; } else { - y1v = y1h + 1; - y2v = y2h - 1; - gdImageLine(im, x1h, y1h, x2h, y1h, color); - gdImageLine(im, x1h, y2h, x2h, y2h, color); - gdImageLine(im, x1v, y1v, x1v, y2v, color); - gdImageLine(im, x2v, y1v, x2v, y2v, color); + if (x1 == x2 || y1 == y2) { + gdImageLine(im, x1, y1, x2, y2, color); + } else { + y1v = y1h + 1; + y2v = y2h - 1; + gdImageLine(im, x1h, y1h, x2h, y1h, color); + gdImageLine(im, x1h, y2h, x2h, y2h, color); + gdImageLine(im, x1v, y1v, x1v, y2v, color); + gdImageLine(im, x2v, y1v, x2v, y2v, color); + } } } diff --git a/ext/gd/tests/bug53154.phpt b/ext/gd/tests/bug53154.phpt new file mode 100644 index 0000000000..6cbae2016c --- /dev/null +++ b/ext/gd/tests/bug53154.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #53154 (Zero-height rectangle has whiskers) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) -- 2.40.0