mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
improve range array overflow error message (#16510)
Improve range array overflow error message Added info about "how much it exceeded" and the maximum allowable array size. Makes debugging easier when encountering this specific issue.
This commit is contained in:
parent
34275564f2
commit
47e440019c
4 changed files with 13 additions and 6 deletions
|
@ -2859,8 +2859,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); \
|
||||
|
@ -2871,8 +2874,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); \
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 %d elements: start=-%d, end=%d, step=1. Calculated size: %d. Maximum size: %d.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue