From: Christoph M. Becker Date: Mon, 20 Jul 2015 21:24:55 +0000 (+0200) Subject: Fix #66387: Stack overflow with imagefilltoborder X-Git-Tag: php-5.6.12RC1~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7f2356665c2569191a946b6fc35b437f0ae1384;p=php 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. --- diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index c75c985c4e..529ba56f1a 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 0000000000..79c49a527b --- /dev/null +++ b/ext/gd/tests/bug66387.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #66387 (Stack overflow with imagefilltoborder) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +ready