com php-src: Fix #74435: Buffer over-read into uninitialized memory: ext/gd/libgd/gd_gif_in.c ext/gd/tests/bug7443 5.gif ext/gd/tests/bug74435.phpt
| From: | Stanislav Malyshev | Date: | Wed, 05 Jul 2017 02:00:57 +0000 |
| Subject: | com php-src: Fix #74435: Buffer over-read into uninitialized memory: ext/gd/libgd/gd_gif_in.c ext/gd/tests/bug7443 5.gif ext/gd/tests/bug74435.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98349@lists.php.net to get a copy of this message | ||
Commit: 8dc4f4dc9e44d1cbfe4654aa6e0dc27c94913938
Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 20 Jun 2017 16:45:42 +0200
Committer: Stanislav Malyshev <stas@php.net> Tue, 4 Jul 2017 19:00:57 -0700
Parents: 5f8380d33e648964d2d5140f329cf2d4c443033c
Branches: PHP-5..6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8dc4f4dc9e44d1cbfe4654aa6e0dc27c94913938
Log:
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.
Bugs:
https://bugs.php.net/74435
Changed paths:
M ext/gd/libgd/gd_gif_in.c
A ext/gd/tests/bug74435.gif
A ext/gd/tests/bug74435.phpt
Diff:
diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c
index f41ec84..e0f0fe3 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
new file mode 100644
index 0000000..92fbb7f
Binary files /dev/null and b/ext/gd/tests/bug74435.gif differ
diff --git a/ext/gd/tests/bug74435.phpt b/ext/gd/tests/bug74435.phpt
new file mode 100644
index 0000000..9d11eb3
--- /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===