From:             php_nospam at ramihyn dot sytes dot net
Operating system: Win32,Linux x86
PHP version:      5.2.0
PHP Bug Type:     Streams related
Bug description:  fread() trouble with stream wrappers

Description:
------------
PHP's fread() function reads only the first 8192 bytes of any file
accessed via a stream wrapper, even if the file is bigger and the
wrappers' stream_eof() method returns false to signal it is NOT the end of
the file.

I expect fread() to repeat calling the wrappers' stream_read()  and
stream_eof() methods until stream_eof() signals the end of file or
stream_read() returns less than the requested 8192 bytes.

I encountered this behaviour with PHP 5.2.0 on Win32 and Linux x86.

Reproduce code:
---------------
<?

class PHP_Bug {
        private $data; private $pos;
        function initializeStream()
        {
                $this->data = str_repeat("-",16399);
                $this->pos = 0;
        }
        function stream_open($fn)
        {
                $this->initializeStream();
                return true;
        }
        function stream_stat()
        {
                $this->initializeStream();
                return 
array(0,0,0100444,"mode"=>0100444,"size"=>strlen($this->data));
        }
        function url_stat()
        {
                return $this->stream_stat();
        }
        function stream_read($cnt)
        {
                echo __METHOD__."(".$cnt.")\n";
                $ret = substr($this->data,$this->pos,$cnt);
                $this->pos += strlen($ret);
                return $ret;
        }
        function stream_eof()
        {
                $ret = ($this->pos >= strlen($this->data));
                echo __METHOD__."=".(($ret)?"true":"false")."\n";
                return $ret;
        }
}

stream_wrapper_register("bug","PHP_Bug");

$fs = filesize("bug://");
$fp = fopen("bug://","r");
$ret = fread($fp,$fs);
fclose($fp);
echo "size is ".strlen($ret)."\n";

?>

Expected result:
----------------
PHP_Bug::stream_read(8192)
PHP_Bug::stream_eof=false
PHP_Bug::stream_read(8192)
PHP_Bug::stream_eof=false
PHP_Bug::stream_read(8192)
PHP_Bug::stream_eof=true
size is 16399

Actual result:
--------------
PHP_Bug::stream_read(8192)
PHP_Bug::stream_eof=false
size is 8192


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

Reply via email to