File tree Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -1538,8 +1538,16 @@ static void php_zend_stream_closer(void *handle) /* {{{ */
1538
1538
1539
1539
static size_t php_zend_stream_fsizer (void * handle ) /* {{{ */
1540
1540
{
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 ) {
1543
1551
return ssb .sb .st_size ;
1544
1552
}
1545
1553
return 0 ;
You can’t perform that action at this time.
0 commit comments