From:             cpuidle at gmx dot de
Operating system: WinXP SP2
PHP version:      5.1.1
PHP Bug Type:     Filesystem function related
Bug description:  fread limited to 8K for local file w/ stream functions

Description:
------------
After using stream_wrapper_register on php 5.1.1, fread is suddenly
limited to 8K block size when reading local(!) files.

This behaviour is
a) not documentated
b) does not happen with PHP 5.0.5
c) not consistent (depending on use of stream_wrapper_register)

I had previously opened bug 35859, but did not receive an answer after the
details had been discovered.

Thanks,
Andi

Reproduce code:
---------------
<?php
class VariableStream {
    var $position, $varname;
    
    function stream_open($path, $mode, $options, &$opened_path) {
        $url = parse_url($path);
        $this->varname = $url['host'];
        $this->position = 0;
        return true;
    }
    
    function stream_read($count) {
        $ret = substr($GLOBALS[$this->varname], $this->position,$count);
        $this->position += strlen($ret);
        return $ret;
    }
    
    function stream_eof() {
        return $this->position >= strlen($GLOBALS[$this->varname]);
    }
    
    function stream_stat() {
        return array('size' => strlen($GLOBALS[$this->varname]));
    }  
    
    function url_stat() {
        return array();
    }
}

function read($filename) {
    if (file_exists($filename) && ($fd = @fopen($filename, 'rb'))) {
        $size = filesize($filename);
        $contents = fread($fd, $size);
    }
    echo("\$filename $filename: \$size: $size
strlen(\$contents):".strlen($contents)."<br/>");
}

// local file
$filename = 'templates/elegant/show.tpl';

// will read entire file
read($filename);

stream_wrapper_register('var', 'VariableStream');

// will only read 8K
read($filename);
?>

Expected result:
----------------
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520
(!!)

Actual result:
--------------
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 9520
$filename templates/elegant/show.tpl: $size: 9520 strlen($contents): 8192
(!!)

-- 
Edit bug report at http://bugs.php.net/?id=35918&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35918&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35918&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35918&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=35918&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=35918&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=35918&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=35918&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=35918&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=35918&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=35918&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=35918&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=35918&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=35918&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35918&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=35918&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=35918&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=35918&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35918&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=35918&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=35918&r=mysqlcfg

Reply via email to