Skip to content

Commit 4d81bf9

Browse files
committed
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6: prevent invalid color index (palette only), may lead to crash Add CVE to #66387 add missing NEWS entry
2 parents 99f8a55 + 6d3fa65 commit 4d81bf9

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
. Fixed bug #72308 (fastcgi_finish_request and logging environment
1616
variables). (Laruence)
1717

18+
- GD:
19+
. Fixed bug #72337 (invalid dimensions can lead to crash) (Pierre)
20+
1821
- Intl:
1922
. Fixed bug #64524 (Add intl.use_exceptions to php.ini-*). (Anatol)
2023

@@ -1005,7 +1008,8 @@ PHP NEWS
10051008

10061009
- GD:
10071010
. Fixed bug #53156 (imagerectangle problem with point ordering). (cmb)
1008-
. Fixed bug #66387 (Stack overflow with imagefilltoborder). (cmb)
1011+
. Fixed bug #66387 (Stack overflow with imagefilltoborder). (CVE-2015-8874)
1012+
(cmb)
10091013
. Fixed bug #70102 (imagecreatefromwebm() shifts colors). (cmb)
10101014
. Fixed bug #66590 (imagewebp() doesn't pad to even length). (cmb)
10111015
. Fixed bug #66882 (imagerotate by -90 degrees truncates image by 1px). (cmb)

ext/gd/libgd/gd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,12 @@ void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
17671767
return;
17681768
}
17691769

1770+
if (!im->trueColor) {
1771+
if ((color > (im->colorsTotal - 1)) || (border > (im->colorsTotal - 1)) || (color < 0)) {
1772+
return;
1773+
}
1774+
}
1775+
17701776
restoreAlphaBlending = im->alphaBlendingFlag;
17711777
im->alphaBlendingFlag = 0;
17721778

ext/gd/tests/github_bug_215.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Github #215 (imagefilltoborder stack overflow when invalid pallete index used)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("gd")) die("skip GD not present");
6+
?>
7+
--FILE--
8+
<?php
9+
$image = imagecreate( 10, 10 );
10+
$bgd = imagecolorallocate( $image, 0, 0, 0 );
11+
$border = imagecolorallocate( $image, 255, 0, 0 );
12+
$fillcolor = imagecolorallocate( $image, 255, 0, 0 );
13+
14+
/* Use unallocated color index */
15+
imagefilltoborder( $image, 0,0, $border+10, $fillcolor);
16+
echo "#1 passes\n";
17+
18+
/* Use negative color index */
19+
imagefilltoborder( $image, 0,0, -$border, $fillcolor);
20+
echo "#2 passes\n";
21+
22+
23+
/* Use unallocated color index */
24+
imagefilltoborder( $image, 0,0, $border, $fillcolor+10);
25+
echo "#3 passes\n";
26+
27+
/* Use negative color index */
28+
imagefilltoborder( $image, 0,0, $border, -$fillcolor);
29+
echo "#4 passes\n";
30+
31+
32+
/* Use negative color index */
33+
imagefilltoborder( $image, 0,0, $border+10, $fillcolor+10);
34+
echo "#5 passes";
35+
36+
37+
?>
38+
--EXPECT--
39+
#1 passes
40+
#2 passes
41+
#3 passes
42+
#4 passes
43+
#5 passes

0 commit comments

Comments
 (0)