php / php/php-src

Supplied range exceeds maximum array size by 0 elements

Open
#22,505 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.