Req #67374 [Com]: Integer Overflow in Memory Usage Functions
| From: | arie_dejong at msn dot com | Date: | Tue, 26 Aug 2014 12:19:37 +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-187278@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: arie_dejong at msn 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:
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);
}
Previous Comments:
------------------------------------------------------------------------
[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