Skip to content

Commit 43abc8f

Browse files
committed
Fixed bug #81430
Check if the runtime cache pointer is NULL before dereferencing it.
1 parent e81ad63 commit 43abc8f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Zend/zend_observer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end(
229229
zend_execute_data *ex = execute_data->prev_execute_data;
230230
while (ex && (!ex->func || ex->func->type == ZEND_INTERNAL_FUNCTION
231231
|| !ZEND_OBSERVABLE_FN(ex->func->common.fn_flags)
232+
|| !&RUN_TIME_CACHE(&ex->func->op_array)
232233
|| !ZEND_OBSERVER_DATA(&ex->func->op_array)
233234
|| ZEND_OBSERVER_DATA(&ex->func->op_array) == ZEND_OBSERVER_NOT_OBSERVED)) {
234235
ex = ex->prev_execute_data;

ext/zend_test/tests/bug81430.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #81430 (Attribute instantiation leaves dangling execute_data pointer)
3+
--INI--
4+
memory_limit=20M
5+
zend_test.observer.enabled=1
6+
zend_test.observer.observe_all=1
7+
--FILE--
8+
<?php
9+
10+
namespace X; // avoid cuf() being optimized away
11+
12+
#[\Attribute]
13+
class A {
14+
public function __construct() {}
15+
}
16+
17+
#[A]
18+
function B() {}
19+
20+
$r = new \ReflectionFunction("X\\B");
21+
var_dump(call_user_func([$r->getAttributes(A::class)[0], 'newInstance']));
22+
23+
array_map("str_repeat", ["\xFF"], [100000000]); // cause a bailout
24+
--EXPECTF--
25+
<!-- init '%s' -->
26+
<file '%s'>
27+
<!-- init X\A::__construct() -->
28+
<X\A::__construct>
29+
</X\A::__construct>
30+
object(X\A)#3 (0) {
31+
}
32+
33+
Fatal error: Allowed memory size of 20971520 bytes exhausted %s in %s on line %d
34+
</file '%s'>

0 commit comments

Comments
 (0)