]> granicus.if.org Git - php/commitdiff
Fix #66387: Stack overflow with imagefilltoborder
authorChristoph M. Becker <cmb@php.net>
Mon, 20 Jul 2015 21:24:55 +0000 (23:24 +0200)
committerChristoph M. Becker <cmb@php.net>
Mon, 20 Jul 2015 21:36:32 +0000 (23:36 +0200)
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
ext/gd/tests/bug66387.phpt [new file with mode: 0644]

index c75c985c4ef8f05f3732f6551741b2d892aa2a7a..529ba56f1ac7bdcee9de279f4756ce7457f27628 100644 (file)
@@ -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 (file)
index 0000000..79c49a5
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #66387 (Stack overflow with imagefilltoborder)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available!');
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(20, 20);
+$c = imagecolorallocate($im, 255, 0, 0);
+imagefilltoborder($im, 0, -999355, $c, $c);
+echo "ready\n";
+?>
+--EXPECT--
+ready