com php-src: Merge branch 'PHP-7.1' into PHP-7.2: ext/gd/libgd/ gd_xbm.c ext/gd/tests/bug77973.phpt ext/ico nv/iconv.c ext/iconv/tests/bug78069.data
ext/ iconv/tests/bug78069.phpt
| From: | Remi Collet | Date: | Wed, 29 May 2019 06:44:06 +0000 |
| Subject: | com php-src: Merge branch 'PHP-7.1' into PHP-7.2: ext/gd/libgd/ gd_xbm.c ext/gd/tests/bug77973.phpt ext/ico nv/iconv.c ext/iconv/tests/bug78069.data ext/ iconv/tests/bug78069.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106421@lists.php.net to get a copy of this message | ||
Commit: 3c0614f3256f90ab524567673c5bc80c8c9988d2
Author: Stanislav Malyshev <stas@php.net> Mon, 27 May 2019 16:49:19 -0700
Committer: Remi Collet <remi@php.net> Wed, 29 May 2019 08:44:06 +0200
Parents: 1b47faea371bff050c37e23d28c76aad0fe89e57
Branches: PHP-7.2.19
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3c0614f3256f90ab524567673c5bc80c8c9988d2
Log:
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
Update NEWS
Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow
Fix #77973: Uninitialized read in gdImageCreateFromXbm
Bugs:
https://bugs.php..net/78069
https://bugs.php.net/77973
Changed paths:
M ext/gd/libgd/gd_xbm.c
A ext/gd/tests/bug77973.phpt
M ext/iconv/iconv.c
A ext/iconv/tests/bug78069.data
A ext/iconv/tests/bug78069.phpt
Diff:
diff --git a/ext/gd/libgd/gd_xbm.c b/ext/gd/libgd/gd_xbm.c
index 1ed0d48..b730732 100644
--- a/ext/gd/libgd/gd_xbm.c
+++ b/ext/gd/libgd/gd_xbm.c
@@ -136,7 +136,11 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd)
}
h[3] = ch;
}
- sscanf(h, "%x", &b);
+ if (sscanf(h, "%x", &b) != 1) {
+ php_gd_error("invalid XBM");
+ gdImageDestroy(im);
+ return 0;
+ }
for (bit = 1; bit <= max_bit; bit = bit << 1) {
gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0);
if (x == im->sx) {
diff --git a/ext/gd/tests/bug77973.phpt b/ext/gd/tests/bug77973.phpt
new file mode 100644
index 0000000..2545dbe
--- /dev/null
+++ b/ext/gd/tests/bug77973.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #77973 (Uninitialized read in gdImageCreateFromXbm)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die("skip gd extension not available");
+if (!function_exists('imagecreatefromxbm')) die("skip imagecreatefromxbm not
available");
+?>
+--FILE--
+<?php
+$contents =
hex2bin("23646566696e6520776964746820320a23646566696e652068656967687420320a737461746963206368617220626974735b5d203d7b0a7a7a787a7a");
+$filepath = __DIR__ . '/bug77973.xbm';
+file_put_contents($filepath, $contents);
+$im = imagecreatefromxbm($filepath);
+var_dump($im);
+?>
+===DONE===
+--EXPECTF--
+Warning: imagecreatefromxbm(): invalid XBM in %s on line %d
+
+Warning: imagecreatefromxbm(): '%s' is not a valid XBM file in %s on line %d
+bool(false)
+===DONE===
+--CLEAN--
+<?php
+unlink(__DIR__ . '/bug77973.xbm');
+?>
diff --git a/ext/iconv/iconv..c b/ext/iconv/iconv.c
index a92395e..781985c 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -1664,7 +1664,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char
*st
* we can do at this point. */
if (*(p1 + 1) == '=') {
++p1;
- --str_left;
+ if (str_left > 1) {
+ --str_left;
+ }
}
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl);
diff --git a/ext/iconv/tests/bug78069.data b/ext/iconv/tests/bug78069.data
new file mode 100644
index 0000000..ebd5d0b
Binary files /dev/null and b/ext/iconv/tests/bug78069.data differ
diff --git a/ext/iconv/tests/bug78069.phpt b/ext/iconv/tests/bug78069.phpt
new file mode 100644
index 0000000..1341a5e
--- /dev/null
+++ b/ext/iconv/tests/bug78069.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #78069 (Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow)
+--SKIPIF--
+<?php
+if (!extension_loaded('iconv')) die('skip ext/iconv required');
+?>
+--FILE--
+<?php
+$hdr = iconv_mime_decode_headers(file_get_contents(__DIR__ . "/bug78069.data"),2);
+var_dump(count($hdr));
+?>
+DONE
+--EXPECT--
+int(1)
+DONE
\ No newline at end of file