From e7f2356665c2569191a946b6fc35b437f0ae1384 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Jul 2015 23:24:55 +0200 Subject: [PATCH 1/2] Fix #66387: Stack overflow with imagefilltoborder The stack overflow is caused by the recursive algorithm in combination with a very large negative coordinate passed to gdImageFillToBorder(). As there is already a clipping for large positive coordinates to the width and height of the image, it seems to be consequent to clip to zero also. --- ext/gd/libgd/gd.c | 4 ++++ ext/gd/tests/bug66387.phpt | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 ext/gd/tests/bug66387.phpt diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index c75c985c4ef..529ba56f1ac 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -1774,9 +1774,13 @@ void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) if (x >= im->sx) { x = im->sx - 1; + } else if (x < 0) { + x = 0; } if (y >= im->sy) { y = im->sy - 1; + } else if (y < 0) { + y = 0; } for (i = x; i >= 0; i--) { diff --git a/ext/gd/tests/bug66387.phpt b/ext/gd/tests/bug66387.phpt new file mode 100644 index 00000000000..79c49a527b4 --- /dev/null +++ b/ext/gd/tests/bug66387.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #66387 (Stack overflow with imagefilltoborder) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +ready From 8461a874543fed9219aa2aaddd1974b5da394235 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Jul 2015 23:40:23 +0200 Subject: [PATCH 2/2] updated NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 71b744b4c08..0cedae6791e 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS . Fixed bug #64878 (304 responses return Content-Type header). (cmb) - GD: + . 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) . Fixed bug #66882 (imagerotate by -90 degrees truncates image by 1px). (cmb)