Req #67374 [Com]: Integer Overflow in Memory Usage Functions
| From: | samuel dot chemla at orange dot com | Date: | Thu, 05 Nov 2015 09:01:28 +0000 |
| Subject: | Req #67374 [Com]: Integer Overflow in Memory Usage Functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197037@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67374&edit=1
ID: 67374
Comment by: samuel dot chemla at orange dot com
Reported by: johannesdahse at gmx dot de
Summary: Integer Overflow in Memory Usage Functions
Status: Open
Type: Feature/Change Request
Package: PHP options/info functions
PHP Version: 5.5.13
Block user comment: N
Private report: N
New Comment:
By the way this shoud be a bug, not a feature request...
Previous Comments:
------------------------------------------------------------------------
[2015-11-05 08:41:04] samuel dot chemla at orange dot com
Hi,
any new on this ?
memory_get_peak_usage() should return an int, which should be 64bit on 64bit systems, but it appears
to be 32bit.
Any reason why ?
NB: I'm on PHP 5.5.30 x64 build on Windows 7 x64
------------------------------------------------------------------------
[2014-08-26 12:19:36] arie_dejong at msn dot com
You can increase the limit by using the negative integer.
$bytes = memory_get_peak_usage();
if($bytes < 0){
$bytes = PHP_INT_MAX + ($bytes - ~PHP_INT_MAX);
}
------------------------------------------------------------------------
[2014-07-05 23:18:03] yohgaki@php.net
I don't use windows often.
AFAIK, int is 32bit under windows regardless of architecture. Therefore, overflow is spec.
Is there any clean/feasible solution? Anyone?
------------------------------------------------------------------------
[2014-06-03 14:42:37] johannesdahse at gmx dot de
Description:
------------
The memory usage functions memory_get_usage() and memory_get_peak_usage() are limited by INTEGER and
can only store the memory usage of 2.147 GB. This results in false reports for higher memory usage.
Tested on Windows 7 64bit, PHP 5.5.13 (64bit and 32bit version).
Test script:
---------------
ini_set("memory_limit", "3G");
$a = array();
for($i=0; $i<22; $i++)
$a[$i] = str_repeat("A", 100000000);
echo memory_get_peak_usage();
Expected result:
----------------
2200227928
Actual result:
--------------
-2094739216
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67374&edit=1