Bug #65239 [NEW]: Strings of 2GB
| From: | pacerier at gmail dot com | Date: | Wed, 10 Jul 2013 17:47:09 +0000 |
| Subject: | Bug #65239 [NEW]: Strings of 2GB | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-180191@lists.php.net to get a copy of this message | ||
From: pacerier at gmail dot com
Operating system: linux
PHP version: 5.3.26
Package: *General Issues
Bug Type: Bug
Bug description:Strings of 2GB
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
--
Edit bug report at https://bugs.php.net/bug.php?id=65239&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65239&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65239&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65239&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65239&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65239&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65239&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65239&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65239&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65239&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65239&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65239&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65239&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65239&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65239&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65239&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65239&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65239&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65239&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65239&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65239&r=mysqlcfg