php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80532 assigning value to string at high index(1e9) results in out of memory error
Submitted: 2020-12-19 07:50 UTC Modified: 2020-12-20 06:18 UTC
From: Srglmr at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.3.25 OS: windows 10 & CentOS 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Srglmr at gmail dot com
New email:
PHP Version: OS:

 

 [2020-12-19 07:50 UTC] Srglmr at gmail dot com
Description:
------------
$X="1";
$X[1e9]=0; // Allowed memory size of 536870912 bytes exhausted (tried to allocate 1000000032 bytes)

Test script:
---------------
$X="1";
$X[1e9]=0; 

Expected result:
----------------
i expect an error telling me that i can't assign by index if the variable is string , but instead it shows out of memory error which is very confusing error 

i encountered the error while trying to do something like this $S[Time()]=0;
thinking that $S is an empty array ( $S = [] ) while it was a string $S = "100"



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-19 14:18 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-12-19 14:18 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

It is allowed to assign by index if the variable is string[1], and
the behavior is well documented[2].  Of course, you need
sufficient memory (and respective memory_limit) to be able to
create such large strings.

[1] <https://3v4l.org/a6J2s>
[2] <https://www.php.net/manual/en/language.types.string.php#language.types.string.substr>
 [2020-12-20 06:18 UTC] Srglmr at gmail dot com
Thanks, it would be much better to have a notice telling me that I assigned a value at an index that is higher than my string length
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC