Bug #78406 [NEW]: Broken file includes with user-defined stream filters
| From: | lisachenko dot it at gmail dot com | Date: | Mon, 12 Aug 2019 17:03:24 +0000 |
| Subject: | Bug #78406 [NEW]: Broken file includes with user-defined stream filters | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222199@lists.php.net to get a copy of this message | ||
From: lisachenko dot it at gmail dot com
Operating system: Windows x64
PHP version: 7.4.0beta2
Package: Streams related
Bug Type: Bug
Bug description:Broken file includes with user-defined stream filters
Description:
------------
Go! AOP framework heavily uses PHP file includes with applied stream
filters like that:
include
'php://filter/read=sample.filter/resource=/some/path/to/php/file
In the latest version this inclusion with applied filter logic can
result in a parse error like this:
Parse error: syntax error, unexpected end of file
Test script:
---------------
<?php
echo 'bug'; // Should be transformed by filter on second include
if (!class_exists(SampleFilter::class)) {
class SampleFilter extends php_user_filter
{
private $data = '';
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in))
{
$this->data .= $bucket->data;
}
if ($closing || feof($this->stream))
{
$consumed = strlen($this->data);
$this->data = str_replace('bug', 'feature',
$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('sample.filter', SampleFilter::class);
$uri = 'php://filter/read=sample.filter/resource='. __FILE__;
$content = file_get_contents($uri);
echo '<pre>', htmlentities($content), '</pre>'; // Looks good
include $uri; // We expect one more "feature" output at line 3
}
Expected result:
----------------
bug
<?php
echo 'feature'; // Should be transformed by filter on second include
if (!class_exists(SampleFilter::class)) {
class SampleFilter extends php_user_filter
{
private $data = '';
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in))
{
$this->data .= $bucket->data;
}
if ($closing || feof($this->stream))
{
$consumed = strlen($this->data);
$this->data = str_replace('feature', 'feature',
$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('sample.filter', SampleFilter::class);
$uri = 'php://filter/read=sample.filter/resource='. __FILE__;
$content = file_get_contents($uri);
echo '<pre>', htmlentities($content), '</pre>'; // Looks good
include $uri; // We expect one more "feature" output at line 3
}
feature
Actual result:
--------------
bug
<?php
echo 'feature'; // Should be transformed by filter on second include
if (!class_exists(SampleFilter::class)) {
class SampleFilter extends php_user_filter
{
private $data = '';
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in))
{
$this->data .= $bucket->data;
}
if ($closing || feof($this->stream))
{
$consumed = strlen($this->data);
$this->data = str_replace('feature', 'feature',
$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('sample.filter', SampleFilter::class);
$uri = 'php://filter/read=sample.filter/resource='. __FILE__;
$content = file_get_contents($uri);
echo '<pre>', htmlentities($content), '</pre>'; // Looks good
include $uri; // We expect one more "feature" output at line 3
}
Parse error: syntax error, unexpected end of file in
H:\Work\go\demos\stream.php on line 38
--
Edit bug report at https://bugs.php.net/bug.php?id=78406&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78406&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78406&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78406&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78406&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78406&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78406&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78406&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78406&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78406&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78406&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78406&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78406&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78406&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78406&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78406&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78406&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78406&r=mysqlcfg