php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29100 fread ignores memory_limit
Submitted: 2004-07-11 22:40 UTC Modified: 2004-07-12 19:20 UTC
From: pickleman78 at sbcglobal dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 4.3.6 OS: WIndows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pickleman78 at sbcglobal dot net
New email:
PHP Version: OS:

 

 [2004-07-11 22:40 UTC] pickleman78 at sbcglobal dot net
Description:
------------
I am getting a crash from PHP when I mistakenly attempt to read 1,761,607,681 bytes from an incoming socket. Now I would reasonably assume that since this is far above the memory limit set in my PHP.ini file 
memory_limit = 8M
I would expect it to stop before even attempting to allocate such a rediculous ammount of memory for the script. In this case it fails with a
FATAL:  emalloc() unable to allocate 1761607681 bytes. Should this be what it does? I would expect it to issue an ERROR as opposed to crashing.

Reproduce code:
---------------
<?php
$fp=fsockopen("http://php.net");
$data=fread($fp,1761607681);
?>

Expected result:
----------------
It would be expected to receive an error as opposed to PHP trying to allocate this memory

Actual result:
--------------
Stated above, causes
FATAL: emalloc() could not......

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-12 19:20 UTC] pollita@php.net
emalloc() deosn't *actually* try to allocate the memory.  It checks your requested amount against the php.ini setting and if it's too high, throws a fatal error.

It has to be a fatal error because your script has outrun its resources, and it's impossible to predict whether or not it can safely continue operations in that condition.
 [2010-03-18 08:34 UTC] nasretdinov at gmail dot com
The this is that this does not lead to normal Fatal error, but to a web server/PHP uncatchable and undebuggable crash.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 30 14:00:02 2025 UTC