diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2017-06-20 16:45:42 +0200 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2017-07-06 07:44:25 +0100 |
commit | 018092125538782b25d3ab6b036f0c8d5968f757 (patch) | |
tree | e29081855924982974f69baf35dac98d622c3b17 | |
parent | 88c521d659521f695e0b9e7fcdded0fc1ee1c53b (diff) | |
download | php-git-018092125538782b25d3ab6b036f0c8d5968f757.tar.gz |
Fix #74435: Buffer over-read into uninitialized memory
The stack allocated color map buffers were not zeroed before usage, and
so undefined palette indexes could cause information leakage.
-rw-r--r-- | ext/gd/libgd/gd_gif_in.c | 3 | ||||
-rw-r--r-- | ext/gd/tests/bug74435.gif | bin | 0 -> 11464 bytes | |||
-rw-r--r-- | ext/gd/tests/bug74435.phpt | 27 |
3 files changed, 30 insertions, 0 deletions
diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c index 74b7493331..76ba152035 100644 --- a/ext/gd/libgd/gd_gif_in.c +++ b/ext/gd/libgd/gd_gif_in.c @@ -147,6 +147,9 @@ gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */ int haveGlobalColormap; gdImagePtr im = 0; + memset(ColorMap, 0, 3 * MAXCOLORMAPSIZE); + memset(localColorMap, 0, 3 * MAXCOLORMAPSIZE); + /*1.4//imageNumber = 1; */ if (! ReadOK(fd,buf,6)) { return 0; diff --git a/ext/gd/tests/bug74435.gif b/ext/gd/tests/bug74435.gif Binary files differnew file mode 100644 index 0000000000..92fbb7ff20 --- /dev/null +++ b/ext/gd/tests/bug74435.gif diff --git a/ext/gd/tests/bug74435.phpt b/ext/gd/tests/bug74435.phpt new file mode 100644 index 0000000000..9d11eb3839 --- /dev/null +++ b/ext/gd/tests/bug74435.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #74435 (Buffer over-read into uninitialized memory) +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('skip gd extension not available'); +?> +--FILE-- +<?php +$im = imagecreatefromgif(__DIR__ . DIRECTORY_SEPARATOR . 'bug74435.gif'); +var_dump($im); +$width = imagesx($im); +$height = imagesy($im); +for ($i = 0; $i < $width; $i += 16) { + for ($j = 0; $j < $height; $j += 16) { + if (($index = imagecolorat($im, $i, $j)) >= 2) { + list($red, $green, $blue, $alpha) = array_values(imagecolorsforindex($im, $index)); + if ($red !== 0 || $green !== 0 || $blue !== 0 || $alpha !== 0) { + echo "unexpected color at ($i, $j)\n"; + } + } + } +} +?> +===DONE=== +--EXPECTF-- +resource(%d) of type (gd) +===DONE=== |