php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65239 Strings of 2GB
Submitted: 2013-07-10 17:47 UTC Modified: 2013-11-08 08:07 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pacerier at gmail dot com Assigned: mumumu (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.26 OS: linux
Private report: No CVE-ID: None
 [2013-07-10 17:47 UTC] pacerier at gmail dot com
Description:
------------
The documentation at http://php.net/manual/en/language.types.string.php states 
that "string can be as large as 2GB".

Now 2GB means 2*1024^3 = 2147483648 bytes.

The documentation is misleading, because strings start to misbehave once they get 
as large as 2147483647 bytes, and not 2147483648 bytes.

Yes I know, it's just a 1 byte difference, but it makes a difference between code 
that works and code that breaks.

Test script:
---------------
error_reporting(E_STRICT|E_ALL);
ini_set('memory_limit', '-1');

$gb = 1024 * 1024 * 1024;
$str = str_repeat('a', 2 * $gb);
echo $str[0]; // Notice: Uninitialized string offset: 0 

Expected result:
----------------
The test script should output the string "a", since 
http://php.net/manual/en/language.types.string.php specifically claims that 
strings can be as large as 2147483648 bytes.

Alternatively, we should re-word the documentation: Strings can be as large as 
2147483647 bytes. Failure to adhere to do so would result in undefined behavior 
(for example, strlen etc).

Actual result:
--------------
Notice: Uninitialized string offset: 0 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-11 06:07 UTC] laruence@php.net
-Package: *General Issues +Package: Documentation problem
 [2013-07-25 09:19 UTC] mumumu@php.net
-Assigned To: +Assigned To: mumumu
 [2013-11-08 08:06 UTC] krakjoe@php.net
Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&revision=332084
Log: #65239 precise maximum
 [2013-11-08 08:07 UTC] krakjoe@php.net
-Status: Assigned +Status: Closed
 [2013-11-08 08:07 UTC] krakjoe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 19:01:31 2024 UTC