Skip to content

Commit cfe77ea

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix bug #77418 - Heap overflow in utf32be_mbc_to_code Add NEWS [ci skip] Add NEWS Fix more issues with encodilng length Fix #77270: imagecolormatch Out Of Bounds Write on Heap Fix bug #77380 (Global out of bounds read in xmlrpc base64 code) Fix bug #77371 (heap buffer overflow in mb regex functions - compile_string_node) Fix bug #77370 - check that we do not read past buffer end when parsing multibytes Fix #77269: Potential unsigned underflow in gdImageScale Fix bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext) Fix bug #77242 (heap out of bounds read in xmlrpc_decode()) Regenerate certs for openssl tests
2 parents d0d0d92 + 1afebfb commit cfe77ea

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
expand_case_fold_string). (Stas)
2121
. Fixed bug #77385 (buffer overflow in fetch_token). (Stas)
2222
. Fixed bug #77394 (Buffer overflow in multibyte case folding - unicode). (Stas)
23+
. Fixed bug #77418 (Heap overflow in utf32be_mbc_to_code). (Stas)
2324

2425
- MySQLnd:
2526
. Fixed bug #75684 (In mysqlnd_ext_plugin.h the plugin methods family has

ext/mbstring/oniguruma/src/utf16_be.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,18 @@ utf16be_is_mbc_newline(const UChar* p, const UChar* end)
8282
}
8383

8484
static OnigCodePoint
85-
utf16be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
85+
utf16be_mbc_to_code(const UChar* p, const UChar* end)
8686
{
8787
OnigCodePoint code;
8888

8989
if (UTF16_IS_SURROGATE_FIRST(*p)) {
90+
if (end - p < 4) return 0;
9091
code = ((((p[0] - 0xd8) << 2) + ((p[1] & 0xc0) >> 6) + 1) << 16)
9192
+ ((((p[1] & 0x3f) << 2) + (p[2] - 0xdc)) << 8)
9293
+ p[3];
9394
}
9495
else {
96+
if (end - p < 2) return 0;
9597
code = p[0] * 256 + p[1];
9698
}
9799
return code;

ext/mbstring/oniguruma/src/utf16_le.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ utf16le_is_mbc_newline(const UChar* p, const UChar* end)
9797
}
9898

9999
static OnigCodePoint
100-
utf16le_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
100+
utf16le_mbc_to_code(const UChar* p, const UChar* end)
101101
{
102102
OnigCodePoint code;
103103
UChar c0 = *p;
104104
UChar c1 = *(p+1);
105105

106106
if (UTF16_IS_SURROGATE_FIRST(c1)) {
107+
if (end - p < 4) return 0;
107108
code = ((((c1 - 0xd8) << 2) + ((c0 & 0xc0) >> 6) + 1) << 16)
108109
+ ((((c0 & 0x3f) << 2) + (p[3] - 0xdc)) << 8)
109110
+ p[2];

ext/mbstring/oniguruma/src/utf32_be.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ utf32be_is_mbc_newline(const UChar* p, const UChar* end)
6767
static OnigCodePoint
6868
utf32be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
6969
{
70+
if (end - p < 4) return 0;
7071
return (OnigCodePoint )(((p[0] * 256 + p[1]) * 256 + p[2]) * 256 + p[3]);
7172
}
7273

ext/mbstring/oniguruma/src/utf32_le.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ utf32le_is_mbc_newline(const UChar* p, const UChar* end)
6767
static OnigCodePoint
6868
utf32le_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
6969
{
70+
if (end - p < 4) return 0;
7071
return (OnigCodePoint )(((p[3] * 256 + p[2]) * 256 + p[1]) * 256 + p[0]);
7172
}
7273

ext/mbstring/tests/bug77418.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #77371 (Heap overflow in utf32be_mbc_to_code)
3+
--SKIPIF--
4+
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5+
--FILE--
6+
<?php
7+
mb_regex_encoding("UTF-32");
8+
var_dump(mb_split("\x00\x00\x00\x5c\x00\x00\x00B","000000000000000000000000000000"));
9+
?>
10+
--EXPECT--
11+
array(1) {
12+
[0]=>
13+
string(30) "000000000000000000000000000000"
14+
}

0 commit comments

Comments
 (0)