Skip to content

Commit f1b2afc

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)
1 parent 6477bb7 commit f1b2afc

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
@@ -340,12 +340,16 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
340340
for (x = xlo; x < xhi; x++) {
341341
if (im->trueColor) {
342342
if (!gdGetInt(&im->tpixels[y][x], in)) {
343-
im->tpixels[y][x] = 0;
343+
php_gd_error("gd2: EOF while reading\n");
344+
gdImageDestroy(im);
345+
return NULL;
344346
}
345347
} else {
346348
int ch;
347349
if (!gdGetByte(&ch, in)) {
348-
ch = 0;
350+
php_gd_error("gd2: EOF while reading\n");
351+
gdImageDestroy(im);
352+
return NULL;
349353
}
350354
im->pixels[y][x] = ch;
351355
}

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)