Skip to content

Commit 9529b89

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents a24659e + 29926c3 commit 9529b89

File tree

4 files changed

+138
-6
lines changed

4 files changed

+138
-6
lines changed

Zend/tests/gh10072-2.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-10072 (PHP crashes when execute_ex is overridden and a trampoline is used from internal code during shutdown)
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
zend_test.replace_zend_execute_ex=1
7+
opcache.jit=disable
8+
--FILE--
9+
<?php
10+
11+
class TrampolineTest {
12+
public function __call(string $name, array $arguments) {
13+
echo 'Trampoline for ', $name, PHP_EOL;
14+
}
15+
}
16+
17+
register_shutdown_function([new TrampolineTest(), 'shutdown']);
18+
?>
19+
--EXPECT--
20+
Trampoline for shutdown

Zend/tests/gh10072.phpt

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

Zend/zend_vm_def.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8723,7 +8723,9 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY, SPEC(OBSERVER))
87238723
SAVE_OPLINE_EX();
87248724
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
87258725
execute_data = EX(prev_execute_data);
8726-
LOAD_OPLINE();
8726+
if (execute_data) {
8727+
LOAD_OPLINE();
8728+
}
87278729
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
87288730
zend_execute_ex(call);
87298731
}
@@ -8775,7 +8777,7 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY, SPEC(OBSERVER))
87758777

87768778
execute_data = EG(current_execute_data);
87778779

8778-
if (!EX(func) || !ZEND_USER_CODE(EX(func)->type) || (call_info & ZEND_CALL_TOP)) {
8780+
if (!execute_data || !EX(func) || !ZEND_USER_CODE(EX(func)->type) || (call_info & ZEND_CALL_TOP)) {
87798781
ZEND_VM_RETURN();
87808782
}
87818783

Zend/zend_vm_execute.h

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)