php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45271 php gives negative memory error with memory limit at 2 gig
Submitted: 2008-06-14 19:13 UTC Modified: 2008-06-15 11:49 UTC
From: paul at paulscripts dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
 [2008-06-14 19:13 UTC] paul at paulscripts dot nl
Description:
------------
php gives the next fatal error:
Fatal error: Allowed memory size of -2147483648 bytes exhausted (tried to allocate 2147221481 bytes) in /root/convert.php on line 6
when trying to use a script with a memory limit of 2gig.

Reproduce code:
---------------
<?php
ini_set('memory_limit', '2048M');
$d = '';
while (true)
{
$d .= 'a';
}


Expected result:
----------------
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 2147221481 bytes) in /root/convert.php on line 6

Actual result:
--------------
Fatal error: Allowed memory size of -2147483648 bytes exhausted (tried to allocate 2147221481 bytes) in /root/convert.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-15 11:49 UTC] derick@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

You simply get an integer overflow. The maximum range is from -2gb to +2gb-1. 2048M is just above this limit so it overflows.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 23:00:02 2025 UTC