com php-src: Fixed #72339 Integer Overflow in _gd2GetHeader () resulting in heap overflow: ext/gd/libgd/gd _gd2.c ext/gd/tests/bug72339.gd ext/gd/te
sts/bug72339.phpt
| From: | Stanislav Malyshev | Date: | Sat, 18 Jun 2016 18:15:10 +0000 |
| Subject: | com php-src: Fixed #72339 Integer Overflow in _gd2GetHeader () resulting in heap overflow: ext/gd/libgd/gd _gd2.c ext/gd/tests/bug72339.gd ext/gd/te sts/bug72339.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92538@lists.php.net to get a copy of this message | ||
Commit: 7722455726bec8c53458a32851d2a87982cf0eac
Author: Pierre Joye <pajoye@php.net> Sat, 18 Jun 2016 20:15:10 +0200
Committer: Anatol Belski <ab@php.net> Sat, 18 Jun 2016 20:15:10 +0200
Parents: 7245bff300d3fa8bacbef7897ff080a6f1c23eba
Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7722455726bec8c53458a32851d2a87982cf0eac
Log:
Fixed #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
Bugs:
https://bugs.php.net/72339
Changed paths:
M ext/gd/libgd/gd_gd2.c
A ext/gd/tests/bug72339.gd
A ext/gd/tests/bug72339.phpt
Diff:
diff --git a/ext/gd/libgd/gd_gd2.c b/ext/gd/libgd/gd_gd2.c
index 6726fee..63e3aef 100644
--- a/ext/gd/libgd/gd_gd2.c
+++ b/ext/gd/libgd/gd_gd2.c
@@ -138,11 +138,18 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers,
in
if (gd2_compressed(*fmt)) {
nc = (*ncx) * (*ncy);
GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
+ if (overflow2(sidx, nc)) {
+ goto fail1;
+ }
sidx = sizeof(t_chunk_info) * nc;
if (sidx <= 0) {
goto fail1;
}
cidx = gdCalloc(sidx, 1);
+ if (cidx == NULL) {
+ goto fail1;
+ }
+
for (i = 0; i < nc; i++) {
if (gdGetInt(&cidx[i].offset, in) != 1) {
gdFree(cidx);
diff --git a/ext/gd/tests/bug72339.gd b/ext/gd/tests/bug72339.gd
new file mode 100644
index 0000000...0634c99
Binary files /dev/null and b/ext/gd/tests/bug72339.gd differ
diff --git a/ext/gd/tests/bug72339.phpt b/ext/gd/tests/bug72339.phpt
new file mode 100644
index 0000000..763ae71
--- /dev/null
+++ b/ext/gd/tests/bug72339.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
+--SKIPIF--
+<?php if (!function_exists("imagecreatefromgd2")) print "skip"; ?>
+--FILE--
+<?php imagecreatefromgd2(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug72339.gd");
?>
+--EXPECTF--
+Warning: imagecreatefromgd2(): gd warning: product of memory allocation multiplication would exceed
INT_MAX, failing operation gracefully
+ in %sbug72339.php on line %d
+
+Warning: imagecreatefromgd2(): '%sbug72339.gd' is not a valid GD2 file in %sbug72339.php
on line %d