Skip to content

Commit b8461eb

Browse files
committed
Fix call after close if multiple filters are attached
1 parent d065a2f commit b8461eb

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Check if multiple filters are closed correctly and never called again after close
3+
--FILE--
4+
<?php
5+
6+
class FirstFilter extends php_user_filter {
7+
public function filter($in, $out, &$consumed, $closing) {
8+
static $closed = 0;
9+
10+
while ($bucket = stream_bucket_make_writeable($in)) {
11+
stream_bucket_append($out, stream_bucket_new($this->stream, $bucket->data));
12+
}
13+
14+
if ($closing) {
15+
$closed++;
16+
}
17+
18+
if ($closed > 0) {
19+
var_dump($closed++);
20+
}
21+
return PSFS_PASS_ON;
22+
}
23+
}
24+
25+
class SecondFilter extends php_user_filter {
26+
public function filter($in, $out, &$consumed, $closing) {
27+
static $closed = 0;
28+
29+
while ($bucket = stream_bucket_make_writeable($in)) {
30+
stream_bucket_append($out, stream_bucket_new($this->stream, $bucket->data));
31+
}
32+
33+
if ($closing) {
34+
$closed++;
35+
}
36+
37+
if ($closed > 0) {
38+
var_dump($closed++);
39+
}
40+
return PSFS_PASS_ON;
41+
}
42+
}
43+
44+
$r = fopen("php://stdout", "w+");
45+
stream_filter_register("first", "FirstFilter");
46+
stream_filter_register("second", "SecondFilter");
47+
$first = stream_filter_prepend($r, "first", STREAM_FILTER_WRITE, []);
48+
$second = stream_filter_prepend($r, "second", STREAM_FILTER_WRITE, []);
49+
fwrite($r, "test\n");
50+
stream_filter_remove($second);
51+
stream_filter_remove($first);
52+
?>
53+
--EXPECT--
54+
test
55+
int(1)
56+
int(1)

main/streams/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS
449449
for(current = filter; current; current = current->next) {
450450
php_stream_filter_status_t status;
451451

452-
status = filter->fops->filter(stream, filter, inp, outp, NULL, flags TSRMLS_CC);
452+
status = filter->fops->filter(stream, current, inp, outp, NULL, flags TSRMLS_CC);
453453
if (status == PSFS_FEED_ME) {
454454
/* We've flushed the data far enough */
455455
return SUCCESS;

0 commit comments

Comments
 (0)