Skip to content

Commit

Permalink
Fix phpGH-14775: range overflow on negative step.
Browse files Browse the repository at this point in the history
overflow occurs since we only deal with positive steps.

close phpGH-14778
  • Loading branch information
devnexen committed Jul 3, 2024
1 parent 6b54d3b commit 15bea9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/array/gh14775.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15bea9e

Please sign in to comment.