xref: /php-src/ext/zend_test/tests/gh11078.phpt (revision bc558bf7)
1--TEST--
2GH-11078 (PHP Fatal error triggers pointer being freed was not allocated and malloc: double free for ptr errors)
3--EXTENSIONS--
4zend_test
5--SKIPIF--
6<?php
7if (getenv('USE_ZEND_ALLOC') === '0') die('skip Zend MM disabled');
8if (PHP_OS_FAMILY === 'Windows') die('skip Windows does not support generic stream casting');
9?>
10--FILE--
11<?php
12
13const MEM = 32 * 1024 * 1024;
14ini_set('memory_limit', MEM);
15
16class CrashingFifo {
17    public $context;
18
19    function stream_open($path, $mode, $options, &$opened_path): bool {
20        return true;
21    }
22
23    function stream_read(int $count): false|string|null {
24        return str_repeat('x', MEM);
25    }
26}
27
28stream_register_wrapper('fifo', CrashingFifo::class);
29$readStream = fopen('fifo://1', 'r');
30zend_test_cast_fread($readStream);
31
32?>
33--EXPECTF--
34Fatal error: Allowed memory size of %d bytes exhausted %s
35