com php-src: Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to i nteger overflow: ext/iconv/iconv.c ext/iconv/tests/bu
g78069.data ext/iconv/tests/bug78069. phpt
| From: | Stanislav Malyshev | Date: | Mon, 27 May 2019 23:32:42 +0000 |
| Subject: | com php-src: Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to i nteger overflow: ext/iconv/iconv.c ext/iconv/tests/bu g78069.data ext/iconv/tests/bug78069. phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106353@lists.php.net to get a copy of this message | ||
Commit: 7cf7148a8f8f4f55fb04de2a517d740bb6253eac
Author: Stanislav Malyshev <stas@php.net> Mon, 27 May 2019 16:32:42 -0700
Parents: ed6dee9a198c904ad5e03113e58a2d2c200f5184
Branches: PHP-7.1
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7cf7148a8f8f4f55fb04de2a517d740bb6253eac
Log:
Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow
Bugs:
https://bugs.php.net/78069
Changed paths:
M ext/iconv/iconv.c
A ext/iconv/tests/bug78069.data
A ext/iconv/tests/bug78069.phpt
Diff:
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index f86d0ae..b4a2abe 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -1673,7 +1673,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