From:             tcarroll at chimesnet dot com
Operating system: linux 2.6.5; glibc 2.3.3
PHP version:      4.3.8
PHP Bug Type:     Output Control
Bug description:  fpassthru and output buffering exhausts memory

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

-- 
Edit bug report at http://bugs.php.net/?id=29940&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=29940&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29940&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29940&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=29940&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=29940&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=29940&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=29940&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=29940&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=29940&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=29940&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=29940&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=29940&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=29940&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=29940&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=29940&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=29940&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=29940&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=29940&r=float

Reply via email to