Skip to content

Commit c0a1ef3

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #72146: Integer overflow on substr_replace
2 parents 567e53e + 33f8dfb commit c0a1ef3

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.10
44

5+
- Standard:
6+
. Fixed bug #72146 (Integer overflow on substr_replace). (cmb)
57

68
29 Jul 2021, PHP 8.0.9
79

ext/standard/string.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,9 @@ PHP_FUNCTION(substr_replace)
23952395
}
23962396
}
23972397

2398-
if ((f + l) > (zend_long)ZSTR_LEN(orig_str)) {
2398+
ZEND_ASSERT(0 <= f && f <= ZEND_LONG_MAX);
2399+
ZEND_ASSERT(0 <= l && l <= ZEND_LONG_MAX);
2400+
if (((size_t) f + l) > ZSTR_LEN(orig_str)) {
23992401
l = ZSTR_LEN(orig_str) - f;
24002402
}
24012403

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)