Skip to content

Commit 23db1ce

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Fix #73869: Signed Integer Overflow gd_io.c Fix #73868: DOS vulnerability in gdImageCreateFromGd2Ctx()
2 parents 3d84aef + cea050b commit 23db1ce

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
@@ -137,6 +137,10 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
137137
GD2_DBG(gd_error("%d Chunks vertically", *ncy));
138138

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

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)