Supplied range exceeds maximum array size by 0 elements
Open
Nobody has claimed this yet.
Bug
Extension: standard
Status: Verified
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$max = (1 << 30) - 1;
$range = range(0, $max);
Resulted in this output:
Fatal error: Uncaught ValueError: The supplied range exceeds the maximum array size by 0 elements: start=0, end=1073741823, step=1. Calculated size: 1073741823. Maximum size: 1073741824. in /in/GPBdM:4
Stack trace:
#0 /in/GPBdM(4): range(0, 1073741823)
#1 {main}
thrown in /in/GPBdM on line 4
Process exited with code 255.
But I expected this output instead:
No error (also the calculated size is wrong, doesn't account for element 0)
PHP Version
8.5.7, 8.4.22
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported range(0, (1 << 30) - 1) case on PHP 8.5.7 or 8.4.22, then trace the range() implementation and its maximum array-size calculation. Done means the valid maximum-sized range no longer raises this error and the reported calculated size accounts for element 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100