Skip to content

Commit 4ae87f4

Browse files
committed
Fix overflow UB in range()
1 parent f26e77b commit 4ae87f4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@ PHP_FUNCTION(array_fill_keys)
27172717
} while (0)
27182718

27192719
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \
2720-
zend_ulong __calc_size = (start - end) / lstep; \
2720+
zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \
27212721
if (__calc_size >= HT_MAX_SIZE - 1) { \
27222722
php_error_docref(NULL, E_WARNING, "The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
27232723
RETURN_FALSE; \
@@ -2887,7 +2887,7 @@ PHP_FUNCTION(range)
28872887
}
28882888

28892889
if (low > high) { /* Negative steps */
2890-
if ((zend_ulong)(low - high) < lstep) {
2890+
if ((zend_ulong)low - high < lstep) {
28912891
err = 1;
28922892
goto err;
28932893
}
@@ -2901,7 +2901,7 @@ PHP_FUNCTION(range)
29012901
}
29022902
} ZEND_HASH_FILL_END();
29032903
} else if (high > low) { /* Positive steps */
2904-
if ((zend_ulong)(high - low) < lstep) {
2904+
if ((zend_ulong)high - low < lstep) {
29052905
err = 1;
29062906
goto err;
29072907
}

0 commit comments

Comments
 (0)