Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2872,9 +2872,9 @@ 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) { \
if (__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: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT " step=" ZEND_LONG_FMT, end, start, (_step)); \
RETURN_THROWS(); \
} \
size = (uint32_t)(__calc_size + 1); \
Expand Down
28 changes: 28 additions & 0 deletions ext/standard/tests/array/gh22505.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-22505 : range() reports the correct calculated size when exceeding HT_MAX_SIZE
--INI--
memory_limit=20G

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this test actually run on CI ??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it is running. range(0, (1 << 30)) code needed minimum 17G.

--SKIPIF--
<?php
if (!getenv('RUN_RESOURCE_HEAVY_TESTS')) die('skip resource-heavy test');
if (getenv('SKIP_SLOW_TESTS')) die('skip slow test');
if (PHP_INT_SIZE != 8) die('skip 64-bit only');
?>
--FILE--
<?php
try {
$arr = range(0, (1 << 30) - 1);
unset($arr);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
range(0, (1 << 30));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
echo 'Done';
?>
--EXPECT--
The supplied range exceeds the maximum array size: start=0 end=1073741824 step=1
Done
Loading