com php-src: Fix #73869: Signed Integer Overflow gd_io.c: ext/gd/libgd/gd_gd2.c ext/gd/tests/bug7386 9.phpt ext/gd/tests/bug73869a.gd2 ext/gd/
tests/bug73869b.gd2

From: Date: Tue, 17 Jan 2017 08:42:45 +0000
Subject: com php-src: Fix #73869: Signed Integer Overflow gd_io.c: ext/gd/libgd/gd_gd2.c ext/gd/tests/bug7386 9.phpt ext/gd/tests/bug73869a.gd2 ext/gd/
tests/bug73869b.gd2
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-96763@lists.php.net to get a copy of this message
Commit: 761cc2b766e040452f026a3b4c3b2c71bcbfb3dd Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 17 Dec 2016 17:06:58 +0100 Committer: Anatol Belski <ab@php.net> Tue, 17 Jan 2017 09:42:45 +0100 Parents: 564a161258e53c05e1d0b02a16568e24d4da3b51 Branches: PHP-7.0.15 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=761cc2b766e040452f026a3b4c3b2c71bcbfb3dd Log: Fix #73869: Signed Integer Overflow gd_io.c GD2 stores the number of horizontal and vertical chunks as words (i.e. 2 byte unsigned). These values are multiplied and assigned to an int when reading the image, what can cause integer overflows.. We have to avoid that, and also make sure that either chunk count is actually greater than zero. If illegal chunk counts are detected, we bail out from reading the image. (cherry picked from commit 5b5d9db3988b829e0b121b74bb3947f01c2796a1) (cherry picked from commit d2274b01cbbadf5516b3ea87ad76fbae18834007) Bugs: https://bugs.php.net/73869 Changed paths: M ext/gd/libgd/gd_gd2.c A ext/gd/tests/bug73869.phpt A ext/gd/tests/bug73869a.gd2 A ext/gd/tests/bug73869b.gd2 Diff: diff --git a/ext/gd/libgd/gd_gd2.c b/ext/gd/libgd/gd_gd2.c index d06f328..83eaaa3 100644 --- a/ext/gd/libgd/gd_gd2.c +++ b/ext/gd/libgd/gd_gd2.c @@ -136,6 +136,10 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in GD2_DBG(php_gd_error("%d Chunks vertically", *ncy)); if (gd2_compressed(*fmt)) { + if (*ncx <= 0 || *ncy <= 0 || *ncx > INT_MAX / *ncy) { + GD2_DBG(printf ("Illegal chunk counts: %d * %d\n", *ncx, *ncy)); + goto fail1; + } nc = (*ncx) * (*ncy); GD2_DBG(php_gd_error("Reading %d chunk index entries", nc)); if (overflow2(sizeof(t_chunk_info), nc)) { diff --git a/ext/gd/tests/bug73869.phpt b/ext/gd/tests/bug73869.phpt new file mode 100644 index 0000000..3cc10a4 --- /dev/null +++ b/ext/gd/tests/bug73869.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #73869 (Signed Integer Overflow gd_io.c) +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('skip gd extension not available'); +?> +--FILE-- +<?php +var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR .. 'bug73869a.gd2')); +var_dump(imagecreatefromgd2(__DIR__ . DIRECTORY_SEPARATOR . 'bug73869b.gd2')); +?> +===DONE=== +--EXPECTF-- +Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d +bool(false) + +Warning: imagecreatefromgd2(): '%s' is not a valid GD2 file in %s on line %d +bool(false) +===DONE=== \ No newline at end of file diff --git a/ext/gd/tests/bug73869a.gd2 b/ext/gd/tests/bug73869a.gd2 new file mode 100644 index 0000000..5060bfd Binary files /dev/null and b/ext/gd/tests/bug73869a.gd2 differ diff --git a/ext/gd/tests/bug73869b.gd2 b/ext/gd/tests/bug73869b.gd2 new file mode 100644 index 0000000..8600126 Binary files /dev/null and b/ext/gd/tests/bug73869b.gd2 differ

« previous php.cvs (#96763) next »