Skip to content

Commit e720bc0

Browse files
cmb69weltling
authored andcommitted
Fix #73868: DOS vulnerability in gdImageCreateFromGd2Ctx()
We must not pretend that there are image data if there are none. Instead we fail reading the image file gracefully. (cherry picked from commit cdb648dc4115ce0722f3cc75e6a65115fc0e56ab) (cherry picked from commit f1b2afc)
1 parent 761cc2b commit e720bc0

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

ext/gd/libgd/gd_gd2.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,16 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
344344
for (x = xlo; x < xhi; x++) {
345345
if (im->trueColor) {
346346
if (!gdGetInt(&im->tpixels[y][x], in)) {
347-
im->tpixels[y][x] = 0;
347+
php_gd_error("gd2: EOF while reading\n");
348+
gdImageDestroy(im);
349+
return NULL;
348350
}
349351
} else {
350352
int ch;
351353
if (!gdGetByte(&ch, in)) {
352-
ch = 0;
354+
php_gd_error("gd2: EOF while reading\n");
355+
gdImageDestroy(im);
356+
return NULL;
353357
}
354358
im->pixels[y][x] = ch;
355359
}

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===

0 commit comments

Comments
 (0)