|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46164 stream_filter_remove() closes the stream
Submitted: 2008-09-24 04:46 UTC Modified: 2008-10-05 01:42 UTC
From: Assigned:
Status: Closed Package: Streams related
PHP Version: 5.3CVS-2008-09-24 (CVS) OS: *
Private report: No CVE-ID: None
 [2008-09-24 04:46 UTC]
Calling stream_filter_remove() closes the stream when the filter is a user filter.

Reproduce code:
class user_filter extends php_user_filter {
        function filter($in, $out, &$consumed, $closing) {
                while($bucket = stream_bucket_make_writeable($in)) {
                        $consumed += $bucket->datalen;
                        stream_bucket_append($out, $bucket);
                return PSFS_PASS_ON;

$fd = fopen('/tmp/test','w');
$filter = stream_filter_append($fd, 'user_filter');

Expected result:

Actual result:
Warning: fclose(): 5 is not a valid stream resource in /tmp/rep.php on line 15


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-28 23:03 UTC] ilia dot cheishvili at gmail dot com
This is caused by telling php_stream_filter_remove() to destruct the stream when it is not necessary.

Here is the patch to fix it:

And here is the test:
 [2008-10-05 01:42 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:25 2019 UTC