Skip to content

Commit 0ecac37

Browse files
nikicsmalyshev
authored andcommitted
Validate subject encoding in mb_split and mb_ereg_match
We were already validating the subject encoding in most functions, but not these two.
1 parent 40fe50d commit 0ecac37

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,11 @@ PHP_FUNCTION(mb_split)
11141114
count--;
11151115
}
11161116

1117+
if (!php_mb_check_encoding(string, string_len,
1118+
_php_mb_regex_mbctype2name(MBREX(current_mbctype)))) {
1119+
RETURN_FALSE;
1120+
}
1121+
11171122
/* create regex pattern buffer */
11181123
if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, MBREX(regex_default_options), MBREX(current_mbctype), MBREX(regex_default_syntax))) == NULL) {
11191124
RETURN_FALSE;
@@ -1203,6 +1208,11 @@ PHP_FUNCTION(mb_ereg_match)
12031208
}
12041209
}
12051210

1211+
if (!php_mb_check_encoding(string, string_len,
1212+
_php_mb_regex_mbctype2name(MBREX(current_mbctype)))) {
1213+
RETURN_FALSE;
1214+
}
1215+
12061216
if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), syntax)) == NULL) {
12071217
RETURN_FALSE;
12081218
}

ext/mbstring/tests/bug77418.phpt

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

0 commit comments

Comments
 (0)