Skip to content

Commit 70523ce

Browse files
smalyshevcmb69
authored andcommitted
Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow
(cherry picked from commit 7cf7148)
1 parent 903b182 commit 70523ce

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
. Fixed bug #77973 (Uninitialized read in gdImageCreateFromXbm).
2020
(CVE-2019-11038) (cmb)
2121

22+
- Iconv:
23+
. Fixed bug #78069 (Out-of-bounds read in iconv.c:_php_iconv_mime_decode()
24+
due to integer overflow). (CVE-2019-11039). (maris dot adam)
25+
2226
- JSON:
2327
. Fixed bug #77843 (Use after free with json serializer). (Nikita)
2428

ext/iconv/iconv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
16631663
* we can do at this point. */
16641664
if (*(p1 + 1) == '=') {
16651665
++p1;
1666-
--str_left;
1666+
if (str_left > 1) {
1667+
--str_left;
1668+
}
16671669
}
16681670

16691671
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl);

ext/iconv/tests/bug78069.data

107 Bytes
Binary file not shown.

ext/iconv/tests/bug78069.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #78069 (Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('iconv')) die('skip ext/iconv required');
6+
?>
7+
--FILE--
8+
<?php
9+
$hdr = iconv_mime_decode_headers(file_get_contents(__DIR__ . "/bug78069.data"),2);
10+
var_dump(count($hdr));
11+
?>
12+
DONE
13+
--EXPECT--
14+
int(1)
15+
DONE

0 commit comments

Comments
 (0)