Skip to content

Commit b727821

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-18901: integer overflow mb_split
2 parents a246102 + 2577e3a commit b727821

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ PHP_FUNCTION(mb_split)
11781178
size_t string_len;
11791179

11801180
int err;
1181-
zend_long count = -1;
1181+
zend_ulong count = -1; /* unsigned, it's a limit and we want to prevent signed overflow */
11821182

11831183
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &arg_pattern, &arg_pattern_len, &string, &string_len, &count) == FAILURE) {
11841184
RETURN_THROWS();

ext/mbstring/tests/gh18901.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
GH-18901 (integer overflow mb_split)
3+
--EXTENSIONS--
4+
mbstring
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists('mb_split')) die('skip mb_split() not available');
8+
?>
9+
--FILE--
10+
<?php
11+
$vals = [PHP_INT_MIN, PHP_INT_MAX, -1, 0, 1];
12+
foreach ($vals as $val) {
13+
var_dump(mb_split('\d', '123', $val));
14+
}
15+
?>
16+
--EXPECT--
17+
array(4) {
18+
[0]=>
19+
string(0) ""
20+
[1]=>
21+
string(0) ""
22+
[2]=>
23+
string(0) ""
24+
[3]=>
25+
string(0) ""
26+
}
27+
array(4) {
28+
[0]=>
29+
string(0) ""
30+
[1]=>
31+
string(0) ""
32+
[2]=>
33+
string(0) ""
34+
[3]=>
35+
string(0) ""
36+
}
37+
array(4) {
38+
[0]=>
39+
string(0) ""
40+
[1]=>
41+
string(0) ""
42+
[2]=>
43+
string(0) ""
44+
[3]=>
45+
string(0) ""
46+
}
47+
array(1) {
48+
[0]=>
49+
string(3) "123"
50+
}
51+
array(1) {
52+
[0]=>
53+
string(3) "123"
54+
}

0 commit comments

Comments
 (0)