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): int
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
21    function onCreate(): bool
22    {
23        echo "fffffffffff\n";
24        return true;
25    }
26
27    function onClose(): void
28    {
29        echo "hello\n";
30    }
31}
32
33stream_filter_register("strtoupper", "strtoupper_filter");
34$fp=fopen($file, "w");
35stream_filter_append($fp,  "strtoupper");
36fread($fp, 1024);
37fwrite($fp, "Thank you\n");
38fclose($fp);
39readfile($file);
40unlink($file);
41?>
42--EXPECTF--
43fffffffffff
44
45Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
46hello
47THANK YOU
48