Skip to content

Commit 6dc20e1

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #72146: Integer overflow on substr_replace
2 parents f556a30 + c0a1ef3 commit 6dc20e1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ext/standard/string.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,9 @@ PHP_FUNCTION(substr_replace)
24612461
}
24622462
}
24632463

2464-
if ((f + l) > (zend_long)ZSTR_LEN(orig_str)) {
2464+
ZEND_ASSERT(0 <= f && f <= ZEND_LONG_MAX);
2465+
ZEND_ASSERT(0 <= l && l <= ZEND_LONG_MAX);
2466+
if (((size_t) f + l) > ZSTR_LEN(orig_str)) {
24652467
l = ZSTR_LEN(orig_str) - f;
24662468
}
24672469

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #72146 (Integer overflow on substr_replace)
3+
--FILE--
4+
<?php
5+
var_dump(substr_replace(["ABCDE"], "123", 3, PHP_INT_MAX));
6+
?>
7+
--EXPECT--
8+
array(1) {
9+
[0]=>
10+
string(6) "ABC123"
11+
}

0 commit comments

Comments
 (0)