1--TEST--
2Bug #35916 (Duplicate calls to stream_bucket_append() lead to a crash)
3--FILE--
4<?php
5$file = __DIR__ . "/bug35916.txt";
6@unlink($file);
7
8class strtoupper_filter extends php_user_filter
9{
10        function filter($in, $out, &$consumed, $closing)
11        {
12        while($bucket=stream_bucket_make_writeable($in)) {
13            $bucket->data = strtoupper($bucket->data);
14            $consumed += $bucket->datalen;
15            stream_bucket_append($out, $bucket);
16            stream_bucket_append($out, $bucket);
17                }
18        return PSFS_PASS_ON;
19        }
20    function onCreate()
21    {
22        echo "fffffffffff\n";
23    }
24    function onClose()
25    {
26        echo "hello\n";
27    }
28}
29
30stream_filter_register("strtoupper", "strtoupper_filter");
31$fp=fopen($file, "w");
32stream_filter_append($fp,  "strtoupper");
33fread($fp, 1024);
34fwrite($fp, "Thank you\n");
35fclose($fp);
36readfile($file);
37unlink($file);
38?>
39--EXPECTF--
40fffffffffff
41
42Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
43hello
44THANK YOU
45