Skip to content

Commit 5d07438

Browse files
committed
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6: Fix #73869: Signed Integer Overflow gd_io.c Fix #73868: DOS vulnerability in gdImageCreateFromGd2Ctx()
2 parents b28c2e2 + d2274b0 commit 5d07438

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

ext/gd/libgd/gd_gd2.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
136136
GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
137137

138138
if (gd2_compressed(*fmt)) {
139+
if (*ncx <= 0 || *ncy <= 0 || *ncx > INT_MAX / *ncy) {
140+
GD2_DBG(printf ("Illegal chunk counts: %d * %d\n", *ncx, *ncy));
141+
goto fail1;
142+
}
139143
nc = (*ncx) * (*ncy);
140144
GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
141145
if (overflow2(sizeof(t_chunk_info), nc)) {
@@ -340,12 +344,16 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
340344
for (x = xlo; x < xhi; x++) {
341345
if (im->trueColor) {
342346
if (!gdGetInt(&im->tpixels[y][x], in)) {
343-
im->tpixels[y][x] = 0;
347+
php_gd_error("gd2: EOF while reading\n");
348+
gdImageDestroy(im);
349+
return NULL;
344350
}
345351
} else {
346352
int ch;
347353
if (!gdGetByte(&ch, in)) {
348-
ch = 0;
354+
php_gd_error("gd2: EOF while reading\n");
355+
gdImageDestroy(im);
356+
return NULL;
349357
}
350358
im->pixels[y][x] = ch;
351359
}

ext/gd/tests/bug73868.gd2

1.03 KB
Binary file not shown.

ext/gd/tests/bug73868.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug 73868 (DOS vulnerability in gdImageCreateFromGd2Ctx())
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73868.gd2'));
10+
?>
11+
===DONE===
12+
--EXPECTF--
13+
Warning: imagecreatefromgd2(): gd2: EOF while reading
14+
in %s on line %d
15+
16+
Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
17+
bool(false)
18+
===DONE===

ext/gd/tests/bug73869.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #73869 (Signed Integer Overflow gd_io.c)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73869a.gd2'));
10+
var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73869b.gd2'));
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
15+
bool(false)
16+
17+
Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
18+
bool(false)
19+
===DONE===

ext/gd/tests/bug73869a.gd2

92 Bytes
Binary file not shown.

ext/gd/tests/bug73869b.gd2

18 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)