Skip to content

Commit f96ebb0

Browse files
cmb69weltling
authored andcommitted
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.
1 parent 4dd0365 commit f96ebb0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ext/gd/libgd/gd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,9 +1774,13 @@ void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
17741774

17751775
if (x >= im->sx) {
17761776
x = im->sx - 1;
1777+
} else if (x < 0) {
1778+
x = 0;
17771779
}
17781780
if (y >= im->sy) {
17791781
y = im->sy - 1;
1782+
} else if (y < 0) {
1783+
y = 0;
17801784
}
17811785

17821786
for (i = x; i >= 0; i--) {

ext/gd/tests/bug66387.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #66387 (Stack overflow with imagefilltoborder)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available!');
6+
?>
7+
--FILE--
8+
<?php
9+
$im = imagecreatetruecolor(20, 20);
10+
$c = imagecolorallocate($im, 255, 0, 0);
11+
imagefilltoborder($im, 0, -999355, $c, $c);
12+
echo "ready\n";
13+
?>
14+
--EXPECT--
15+
ready

0 commit comments

Comments
 (0)