php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66543 Incorrect closing for userland stream filter applied to the PHAR file
Submitted: 2014-01-22 11:56 UTC Modified: 2021-07-28 10:26 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: lisachenko dot it at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Streams related
PHP Version: 5.5.8 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lisachenko dot it at gmail dot com
New email:
PHP Version: OS:

 

 [2014-01-22 11:56 UTC] lisachenko dot it at gmail dot com
Description:
------------
When a custom stream filter applied to a phar archive then "closing" flag is not set during the call to the php_user_filter::filter($in, $out, &$consumed, $closing)

So, user filter can not terminate filtration correctly and typically returns PSFS_FEED_ME to read more data to process after eof and this results into empty string from the filter.

When executing stream_get_meta_data($this->stream) inside filter() method I can see that eof flag for stream is already set, but "closing" flag is set to false:
array(9) {
  ["wrapper_type"]=>
  string(3) "PHP"
  ["stream_type"]=>
  string(11) "phar stream"
  ["mode"]=>
  string(2) "rb"
  ["unread_bytes"]=>
  int(0)
  ["seekable"]=>
  bool(true)
  ["uri"]=>
  string(53) "php://filter/read=test/resource=phar://test.phar/Test"
  ["timed_out"]=>
  bool(false)
  ["blocked"]=>
  bool(true)
  ["eof"]=>
  bool(true)
}

Test script:
---------------
<?php
// Require phar.readonly = Off in php.ini
class PharStreamFilter extends php_user_filter
{
    protected $data = '';

    public function filter($in, $out, &$consumed, $closing){
        while ($bucket = stream_bucket_make_writeable($in)) {
            $this->data .= $bucket->data;
        }
        if ($closing) {
            $consumed += strlen($this->data);
            $bucket    = stream_bucket_new($this->stream, $this->data);
            stream_bucket_append($out, $bucket);
            return PSFS_PASS_ON;
        }
        return PSFS_FEED_ME;
    }
}

stream_filter_register('test', 'PharStreamFilter');
$source = 'Test';
$phar   = new Phar('test.phar');
$phar['Test'] = $source;

$actual = file_get_contents('php://filter/read=test/resource=phar://test.phar/Test');
echo ($actual==$source) ? 'OK' : 'FAIL';

Expected result:
----------------
I'm expecting that filter will receive "closing" flag correctly and all data will be returned from the filter correctly. So output should be:

OK

Actual result:
--------------
Filter doesn't receive "closing" flag for phar stream and returns an empty string. Output will be:

FAIL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-27 20:56 UTC] den at nurfuerspam dot de
I have the same issue whit compress.zlib:// streams on Ubuntu in PHP 7.0.13, PHP 5.5.9 and others to.
 [2021-07-28 10:26 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-28 10:26 UTC] cmb@php.net
This is basically a duplicate of bug #77069 (fixed as of 7.4.14
and 8.0.1, respectively).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 14:01:30 2024 UTC