Skip to content

Commit 2e4f76d

Browse files
committed
Merge branch 'PHP-7.4'
2 parents fb363f7 + b01824e commit 2e4f76d

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

Zend/tests/bug78406.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Bug #78406: Broken file includes with user-defined stream filters
3+
--FILE--
4+
<?php
5+
6+
echo "bug\n"; // Should be transformed by filter on second include
7+
8+
if (!class_exists(SampleFilter::class)) {
9+
class SampleFilter extends php_user_filter
10+
{
11+
private $data = '';
12+
13+
public function filter($in, $out, &$consumed, $closing)
14+
{
15+
while ($bucket = stream_bucket_make_writeable($in))
16+
{
17+
$this->data .= $bucket->data;
18+
}
19+
20+
if ($closing || feof($this->stream))
21+
{
22+
$consumed = strlen($this->data);
23+
24+
$this->data = str_replace('bug', 'feature', $this->data);
25+
26+
$bucket = stream_bucket_new($this->stream, $this->data);
27+
stream_bucket_append($out, $bucket);
28+
29+
return PSFS_PASS_ON;
30+
}
31+
32+
return PSFS_FEED_ME;
33+
}
34+
}
35+
stream_filter_register('sample.filter', SampleFilter::class);
36+
$uri = 'php://filter/read=sample.filter/resource='. __FILE__;
37+
38+
include $uri; // We expect one more "feature" output at line 3
39+
}
40+
41+
?>
42+
--EXPECT--
43+
bug
44+
feature

main/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,16 @@ static void php_zend_stream_closer(void *handle) /* {{{ */
15381538

15391539
static size_t php_zend_stream_fsizer(void *handle) /* {{{ */
15401540
{
1541-
php_stream_statbuf ssb;
1542-
if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
1541+
php_stream *stream = handle;
1542+
php_stream_statbuf ssb;
1543+
1544+
/* File size reported by stat() may be inaccurate if stream filters are used.
1545+
* TODO: Should stat() be generally disabled if filters are used? */
1546+
if (stream->readfilters.head) {
1547+
return 0;
1548+
}
1549+
1550+
if (php_stream_stat(stream, &ssb) == 0) {
15431551
return ssb.sb.st_size;
15441552
}
15451553
return 0;

0 commit comments

Comments
 (0)