Skip to content

Commit b1aafcb

Browse files
committed
Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow
1 parent 3b14a5a commit b1aafcb

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

ext/iconv/iconv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
15801580
* we can do at this point. */
15811581
if (*(p1 + 1) == '=') {
15821582
++p1;
1583-
--str_left;
1583+
if (str_left > 1) {
1584+
--str_left;
1585+
}
15841586
}
15851587

15861588
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)