|
| 1 | +--TEST-- |
| 2 | +GH-10072 (PHP crashes when execute_ex is overridden and a trampoline is used from internal code) |
| 3 | +--EXTENSIONS-- |
| 4 | +zend_test |
| 5 | +--INI-- |
| 6 | +zend_test.replace_zend_execute_ex=1 |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +class DummyStreamWrapper |
| 10 | +{ |
| 11 | + /** @var resource|null */ |
| 12 | + public $context; |
| 13 | + |
| 14 | + /** @var resource|null */ |
| 15 | + public $handle; |
| 16 | + |
| 17 | + |
| 18 | + public function stream_cast(int $castAs) |
| 19 | + { |
| 20 | + return $this->handle; |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | + public function stream_close(): void |
| 25 | + { |
| 26 | + } |
| 27 | + |
| 28 | + public function stream_open(string $path, string $mode, int $options = 0, ?string &$openedPath = null): bool |
| 29 | + { |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + public function stream_read(int $count) |
| 35 | + { |
| 36 | + return 0; |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + public function stream_seek(int $offset, int $whence = SEEK_SET): bool |
| 41 | + { |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + public function stream_set_option(int $option, int $arg1, ?int $arg2): bool |
| 47 | + { |
| 48 | + return false; |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + public function stream_stat() |
| 53 | + { |
| 54 | + return []; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public function stream_tell() |
| 59 | + { |
| 60 | + return []; |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + public function stream_truncate(int $newSize): bool |
| 65 | + { |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + public function stream_write(string $data) |
| 71 | + { |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | + public function unlink(string $path): bool |
| 76 | + { |
| 77 | + return false; |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +class TrampolineTest { |
| 82 | + /** @var resource|null */ |
| 83 | + public $context; |
| 84 | + |
| 85 | + /** @var object|null */ |
| 86 | + private $wrapper; |
| 87 | + |
| 88 | + public function __call(string $name, array $arguments) { |
| 89 | + if (!$this->wrapper) { |
| 90 | + $this->wrapper = new DummyStreamWrapper(); |
| 91 | + } |
| 92 | + echo 'Trampoline for ', $name, PHP_EOL; |
| 93 | + return $this->wrapper->$name(...$arguments); |
| 94 | + } |
| 95 | + |
| 96 | +} |
| 97 | + |
| 98 | +stream_wrapper_register('custom', TrampolineTest::class); |
| 99 | + |
| 100 | + |
| 101 | +$fp = fopen("custom://myvar", "r+"); |
| 102 | +?> |
| 103 | +--EXPECT-- |
| 104 | +Trampoline for stream_open |
| 105 | +Trampoline for stream_close |
0 commit comments