mirror of
https://github.com/php/php-src.git
synced 2026-04-25 08:58:28 +02:00
Merge branch 'PHP-8.0'
* PHP-8.0: Avoid signed integer overflow in substr()
This commit is contained in:
@@ -2177,7 +2177,7 @@ PHP_FUNCTION(substr)
|
||||
/* if "from" position is negative, count start position from the end
|
||||
* of the string
|
||||
*/
|
||||
if ((size_t)-f > ZSTR_LEN(str)) {
|
||||
if (-(size_t)f > ZSTR_LEN(str)) {
|
||||
f = 0;
|
||||
} else {
|
||||
f = (zend_long)ZSTR_LEN(str) + f;
|
||||
@@ -2191,7 +2191,7 @@ PHP_FUNCTION(substr)
|
||||
/* if "length" position is negative, set it to the length
|
||||
* needed to stop that many chars from the end of the string
|
||||
*/
|
||||
if ((size_t)(-l) > ZSTR_LEN(str) - (size_t)f) {
|
||||
if (-(size_t)l > ZSTR_LEN(str) - (size_t)f) {
|
||||
l = 0;
|
||||
} else {
|
||||
l = (zend_long)ZSTR_LEN(str) - f + l;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
substr() with PHP_INT_MIN offset or length
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(substr('x', PHP_INT_MIN));
|
||||
var_dump(substr('x', 0, PHP_INT_MIN));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(1) "x"
|
||||
string(0) ""
|
||||
Reference in New Issue
Block a user