|  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
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 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:
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
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) {
  string(3) "PHP"
  string(11) "phar stream"
  string(2) "rb"
  string(53) "php://filter/read=test/resource=phar://test.phar/Test"

Test script:
// 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:


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



Add a Patch

Pull Requests

Add a Pull Request


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]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-28 10:26 UTC]
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: Mon Jul 15 14:01:28 2024 UTC