|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78340 Include of stream wrapper not reading whole file
Submitted: 2019-07-28 11:19 UTC Modified: 2019-07-29 08:05 UTC
From: Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4-snapshot OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2019-07-28 11:19 UTC]
When reading files from a stream wrapper, not all bytes are read.

Test script:

class lib {
  public static $files= [];

  private $bytes, $pos;

  function stream_open($path, $mode, $options, $opened_path) {
    $this->bytes= self::$files[$path];
    $this->pos= 0;
    $this->ino= crc32($path);
    return true;

  function stream_read($count) {
    $chunk= substr($this->bytes, $this->pos, $count);
    $this->pos+= strlen($chunk);
    return $chunk;

  function stream_eof() {
    return $this->pos >= strlen($this->bytes);

  function stream_close() {
    $this->bytes= null;

  function stream_stat() {
    return [
      'dev'   => 3632233996,
      'size'  => strlen($this->bytes),
      'ino'   => $this->ino

  function stream_set_option($option, $arg1, $arg2) {
    return false;

$fill= str_repeat('.', $argv[1] ?? 0);
lib::$files['lib://test.php']= '<?php /* '.$fill.' */ function test() { echo "Works!\n"; }';
stream_wrapper_register('lib', lib::class);


Expected result:
$ /cygdrive/c/tools/php-7.3.6-nts-Win32-VC15-x64/php wrapper.php 8192

Actual result:
$ /cygdrive/c/tools/php-7.4snap-nts-windows-vc15-x64/php wrapper.php 8192

Warning: Unterminated comment starting line 1 in lib://test.php on line 1

Fatal error: Uncaught Error: Call to undefined function test() in C:\tools\cygwin\home\Timm\devel\xp\core\wrapper.php:47
Stack trace:
#0 {main}


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-28 11:24 UTC]
-Summary: Segfault in zend_objects_store_put +Summary: Stream wrappers not reading correctly -Operating System: Linux +Operating System: Windows -PHP Version: 7.4.0beta1 +PHP Version: 7.4-snapshot
 [2019-07-28 11:24 UTC]
Correct metadata
 [2019-07-29 07:47 UTC]
On linux this prints "Works!" for me (checked with and without opcache).
 [2019-07-29 07:49 UTC]
-Status: Open +Status: Verified
 [2019-07-29 07:49 UTC]
Sorry, I missed the fact that there is a CLI arg.
 [2019-07-29 07:56 UTC]
-Assigned To: +Assigned To: nikic
 [2019-07-29 08:05 UTC]
-Summary: Stream wrappers not reading correctly +Summary: Include of stream wrapper not reading whole file
 [2019-07-29 08:13 UTC]
Automatic comment on behalf of
Log: Fixed bug #78340
 [2019-07-29 08:13 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 13:01:24 2019 UTC