Skip to content

Commit

Permalink
Fix #73868: DOS vulnerability in gdImageCreateFromGd2Ctx()
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cmb69 authored and weltling committed Jan 17, 2017
1 parent 6477bb7 commit f1b2afc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/gd/libgd/gd_gd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,16 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
for (x = xlo; x < xhi; x++) {
if (im->trueColor) {
if (!gdGetInt(&im->tpixels[y][x], in)) {
im->tpixels[y][x] = 0;
php_gd_error("gd2: EOF while reading\n");
gdImageDestroy(im);
return NULL;
}
} else {
int ch;
if (!gdGetByte(&ch, in)) {
ch = 0;
php_gd_error("gd2: EOF while reading\n");
gdImageDestroy(im);
return NULL;
}
im->pixels[y][x] = ch;
}
Expand Down
Binary file added ext/gd/tests/bug73868.gd2
Binary file not shown.
18 changes: 18 additions & 0 deletions ext/gd/tests/bug73868.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug 73868 (DOS vulnerability in gdImageCreateFromGd2Ctx())
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
?>
--FILE--
<?php
var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73868.gd2'));
?>
===DONE===
--EXPECTF--
Warning: imagecreatefromgd2(): gd2: EOF while reading
in %s on line %d

Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d
bool(false)
===DONE===

0 comments on commit f1b2afc

Please sign in to comment.