Fix GH-14775: range overflow on negative step.

overflow occurs since we only deal with positive steps.

close GH-14778
This commit is contained in:
David Carlier 2024-07-03 06:39:29 +01:00
parent 6b54d3b26f
commit 15bea9ed74
No known key found for this signature in database
GPG Key ID: D308BD11AB42D054
3 changed files with 21 additions and 1 deletions

6
NEWS
View File

@ -29,7 +29,11 @@ PHP NEWS
(David Carlier)
- Shmop:
. Fixed bug GH-14537 (shmop Windows 11 crashes the process). (nielsdos)
. Fixed bug GH-14537 (shmop Windows 11 crashes the process). (nielsdos)
- Standard:
. Fixed bug GH-14775 (range function overflow with negative step argument).
(David Carlier)
20 Jun 2024, PHP 8.3.9

View File

@ -2887,6 +2887,10 @@ PHP_FUNCTION(range)
step = Z_LVAL_P(user_step);
/* We only want positive step values. */
if (step < 0) {
if (UNEXPECTED(step == ZEND_LONG_MIN)) {
zend_argument_value_error(3, "must be greater than " ZEND_LONG_FMT, step);
RETURN_THROWS();
}
is_step_negative = true;
step *= -1;
}

View File

@ -0,0 +1,12 @@
--TEST--
GH-14775: Range negative step overflow
--FILE--
<?php
$var = -PHP_INT_MAX - 1;
try {
range($var,1,$var);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}
--EXPECTF--
range(): Argument #3 ($step) must be greater than %s