php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29940 fpassthru and output buffering exhausts memory
Submitted: 2004-09-01 23:59 UTC Modified: 2004-09-02 08:25 UTC
From: tcarroll at chimesnet dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.8 OS: linux 2.6.5; glibc 2.3.3
Private report: No CVE-ID: None
 [2004-09-01 23:59 UTC] tcarroll at chimesnet dot com
Description:
------------
If output buffering is used and a large file is opened and the resulting handle is passed to fpassthru, memory exhaustion occurs.

The optimization in _php_stream_passthru mmaps the entire file into the address space.  During the PHPWRITE call sequence, an output buffer is allocated the size of the mmap'ed file.  If the file is large, a large allocation occurs.

Semantically, fpassthru should not cause memory exhaustion.  Generally, large writes to buffered IO should generate several flushes to the underlying IO device instead of allocating one large buffer to store the contents.  This limits the applications of fpassthru to where the file size is known before hand and where the size is smaller than memory_limit or available memory.

This was earlier reported as #20772

Reproduce code:
---------------
Create a file larger than memory_limit or available memory

memory_limit = 8M
dd if=/dev/zero of=bigfile bs=1M count=128

<?php
$fp = fopen('./bigfile','r');
fpassthru($fp);
?>

Expected result:
----------------
The entire output of the file

Actual result:
--------------
No output


PHP Fatal error:  Allowed memory size of 8388608 bytes exhausted (tried to allocate 134213632 bytes) in /home/tcarroll/public_html/passthru.php on line 14

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-02 08:25 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #29922.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 22:01:29 2024 UTC