php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27511 fread crashes Apache with mistakenly big length
Submitted: 2004-03-06 04:53 UTC Modified: 2004-03-06 14:11 UTC
From: patrick at borgeat dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.0.0b4 (beta4) OS: Windows 2000 SR4
Private report: No CVE-ID: None
 [2004-03-06 04:53 UTC] patrick at borgeat dot de
Description:
------------
As I mistakenly tried to read a very large number of bytes (1078508183) (more than are in the file) with fread, the Site doesn't react anymore and i get a apache.exe Task in my Tasklist consuming an average of 80% CPU Load (with a 1300 Mhz Machine) which can't be stopped (maybe also due to missing rights). Also the file is blocked.

Never tested this on Linux, but I think if a server does this mistakenly several times at once the whole server enviroment would crash.

I run Apache 2.0.48 with PHP 5.0.0b4 as Apache2 Handler on Windows 2000 SR4 on FAT32 Filesystem.

Reproduce code:
---------------
(in my case test was a textfile with the 3 Letters "AAA")

<?
$fp = fopen("test",r");
$res = fread($fp,1078508183);
echo $res
fclose($fp);
?>



Expected result:
----------------
I expected PHP to be as smart (as it is with smaller numbers for example like 50 000) to write only 3 Bytes and output "AAA".

Actual result:
--------------
Apache Task isn't stopable and runs @ Average of 80% CPU Load

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-06 07:07 UTC] patrick at borgeat dot de
I forgot a Semikolon (;) after "echo $res", sorry!
 [2004-03-06 14:11 UTC] iliaa@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

When you call fread() PHP will try to allocate enough 
memory to store all of the data that you want to read. 
Meaning that in your case it'll try to allocate 
approximately 1078508183 bytes. This fails and causes the 
script to exit OR if you have enough memory and/or swap try 
to allocate this much memory which would take a VERY long 
time. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 00:01:33 2024 UTC