Skip to content

Commit 0323fff

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 5bb987b + f47a45e commit 0323fff

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ext/mbstring/mbstring.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,16 @@ PHP_FUNCTION(mb_substr)
23262326
Z_PARAM_STR_OR_NULL(encoding)
23272327
ZEND_PARSE_PARAMETERS_END();
23282328

2329+
if (from == ZEND_LONG_MIN) {
2330+
zend_argument_value_error(2, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (ZEND_LONG_MIN + 1), ZEND_LONG_MAX);
2331+
RETURN_THROWS();
2332+
}
2333+
2334+
if (!len_is_null && len == ZEND_LONG_MIN) {
2335+
zend_argument_value_error(3, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (ZEND_LONG_MIN + 1), ZEND_LONG_MAX);
2336+
RETURN_THROWS();
2337+
}
2338+
23292339
const mbfl_encoding *enc = php_mb_get_encoding(encoding, 4);
23302340
if (!enc) {
23312341
RETURN_THROWS();

ext/mbstring/tests/gh16360.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-16320 mb_substr overflow from negative length
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
try {
8+
mb_substr("abcd", PHP_INT_MIN, 4, "UTF-8");
9+
} catch (\ValueError $e) {
10+
echo $e->getMessage() . PHP_EOL;
11+
}
12+
try {
13+
mb_substr("abcd", 0, PHP_INT_MIN, "UTF-8");
14+
} catch (\ValueError $e) {
15+
echo $e->getMessage() . PHP_EOL;
16+
}
17+
var_dump(mb_substr("abcd", PHP_INT_MAX, PHP_INT_MAX, "UTF-8"));
18+
?>
19+
--EXPECTF--
20+
mb_substr(): Argument #2 ($start) must be between %s and %s
21+
mb_substr(): Argument #3 ($length) must be between %s and %s
22+
string(0) ""
23+

0 commit comments

Comments
 (0)