Skip to content

Commit bc4140d

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Detect overlarge step for character range()
2 parents 52435f9 + c567016 commit bc4140d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@ PHP_FUNCTION(range)
27302730
high = (unsigned char)Z_STRVAL_P(zhigh)[0];
27312731

27322732
if (low > high) { /* Negative Steps */
2733-
if (lstep <= 0) {
2733+
if (low - high < lstep || lstep <= 0) {
27342734
err = 1;
27352735
goto err;
27362736
}
@@ -2747,7 +2747,7 @@ PHP_FUNCTION(range)
27472747
}
27482748
} ZEND_HASH_FILL_END();
27492749
} else if (high > low) { /* Positive Steps */
2750-
if (lstep <= 0) {
2750+
if (high - low < lstep || lstep <= 0) {
27512751
err = 1;
27522752
goto err;
27532753
}

ext/standard/tests/array/range_errors.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ try {
4747
echo $e->getMessage(), "\n";
4848
}
4949

50+
echo "\n\n-- Testing ( (low < high) && (high-low < step) ) for characters --\n";
51+
try {
52+
var_dump(range('a', 'z', 100));
53+
} catch (\ValueError $e) {
54+
echo $e->getMessage(), "\n";
55+
}
56+
57+
echo "\n\n-- Testing ( (low > high) && (low-high < step) ) for characters --\n";
58+
try {
59+
var_dump(range('z', 'a', 100));
60+
} catch (\ValueError $e) {
61+
echo $e->getMessage(), "\n";
62+
}
63+
5064
echo "\n-- Testing other conditions --\n";
5165
try {
5266
var_dump( range(-1, -2, 2) );
@@ -97,6 +111,14 @@ range(): Argument #3 ($step) must not exceed the specified range
97111
-- Testing ( (low > high) && (low-high < step) ) --
98112
range(): Argument #3 ($step) must not exceed the specified range
99113

114+
115+
-- Testing ( (low < high) && (high-low < step) ) for characters --
116+
range(): Argument #3 ($step) must not exceed the specified range
117+
118+
119+
-- Testing ( (low > high) && (low-high < step) ) for characters --
120+
range(): Argument #3 ($step) must not exceed the specified range
121+
100122
-- Testing other conditions --
101123
range(): Argument #3 ($step) must not exceed the specified range
102124
range(): Argument #3 ($step) must be of type int|float, string given

0 commit comments

Comments
 (0)