php.net |  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: lbarnaud@php.net 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] lbarnaud@php.net
Description:
------------
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;
        }
}
stream_filter_register('user_filter','user_filter');

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

Expected result:
----------------
bool(true)

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

Patches

Pull Requests

History

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: http://pastebin.com/fabd37ae

And here is the test: http://pastebin.com/f42d8848c
 [2008-10-05 01:42 UTC] lbarnaud@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC