Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,8 +2861,11 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end, _step) do { \
double __calc_size = ((start - end) / (_step)) + 1; \
if (__calc_size >= (double)HT_MAX_SIZE) { \
double __exceed_by = __calc_size - (double)HT_MAX_SIZE; \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=%0.1f end=%0.1f step=%0.1f", end, start, (_step)); \
"The supplied range exceeds the maximum array size by %.1f elements: " \
"start=%.1f, end=%.1f, step=%.1f. Max size: %.0f", \
__exceed_by, end, start, (_step), (double)HT_MAX_SIZE); \
RETURN_THROWS(); \
} \
size = (uint32_t)_php_math_round(__calc_size, 0, PHP_ROUND_HALF_UP); \
Expand All @@ -2873,8 +2876,12 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end, _step) do { \
zend_ulong __calc_size = ((zend_ulong) start - end) / (_step); \
if (__calc_size >= HT_MAX_SIZE - 1) { \
uint64_t __excess = __calc_size - (HT_MAX_SIZE - 1); \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT " step=" ZEND_LONG_FMT, end, start, (_step)); \
"The supplied range exceeds the maximum array size by %" PRIu64 " elements: " \
"start=" ZEND_LONG_FMT ", end=" ZEND_LONG_FMT ", step=" ZEND_LONG_FMT ". " \
"Calculated size: %" PRIu64 ", Maximum size: %" PRIu64 ".", \
__excess, end, start, (_step), (uint64_t)__calc_size, (uint64_t)HT_MAX_SIZE); \
RETURN_THROWS(); \
} \
size = (uint32_t)(__calc_size + 1); \
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/range/range_bug70239_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ try {
}
?>
--EXPECTF--
The supplied range exceeds the maximum array size: start=0 end=%d step=1
The supplied range exceeds the maximum array size by %d elements: start=0, end=%d, step=1. Calculated size: %d, Maximum size: %d.
2 changes: 1 addition & 1 deletion ext/standard/tests/array/range/range_bug70239_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ try {
}
?>
--EXPECTF--
The supplied range exceeds the maximum array size: start=-%d end=0 step=1
The supplied range exceeds the maximum array size by %d elements: start=-%d, end=0, step=1. Calculated size: %d, Maximum size: %d.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ try {
}
?>
--EXPECTF--
The supplied range exceeds the maximum array size: start=0.0 end=100000000000.0 step=0.1
The supplied range exceeds the maximum array size: start=-%d end=%d step=1
The supplied range exceeds the maximum array size by %f elements: start=0.0, end=%f, step=0.1. Max size: %d
The supplied range exceeds the maximum array size by %f elements: start=-%f, end=%f, step=1. Calculated size: %d, Maximum size: %d.