Bug #66543 [Com]: Incorrect closing for userland stream filter applied to the PHAR file

From: Date: Sun, 27 Nov 2016 20:56:07 +0000
Subject: Bug #66543 [Com]: Incorrect closing for userland stream filter applied to the PHAR file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205663@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66543&edit=1

 ID:                 66543
 Comment by:         den at nurfuerspam dot de
 Reported by:        lisachenko dot it at gmail dot com
 Summary:            Incorrect closing for userland stream filter applied
                     to the PHAR file
 Status:             Open
 Type:               Bug
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        5.5.8
 Block user comment: N
 Private report:     N

 New Comment:

I have the same issue whit compress.zlib:// streams on Ubuntu in PHP 7.0.13, PHP 5.5.9 and others
to.


Previous Comments:
------------------------------------------------------------------------
[2014-01-22 11:56:02] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=66543&edit=1


Thread (3 messages)

« previous php.bugs (#205663) next »