Bug #66543 [NEW]: Incorrect closing for userland stream filter applied to the PHAR file
From: lisachenko dot it at gmail dot com
Operating system: Windows
PHP version: 5.5.8
Package: Streams related
Bug Type: Bug
Bug description:Incorrect closing for userland stream filter applied to the PHAR file
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 bug report at https://bugs.php.net/bug.php?id=66543&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66543&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66543&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66543&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66543&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66543&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66543&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66543&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66543&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66543&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66543&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66543&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66543&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66543&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66543&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66543&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66543&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66543&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66543&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66543&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66543&r=mysqlcfg
Thread (3 messages)
- lisachenko dot it at gmail dot com