Skip to content

Fixed bug #81430 Check if runtime cache pointer is NULL before dereferencing #7665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Zend/zend_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end(
zend_execute_data *ex = execute_data->prev_execute_data;
while (ex && (!ex->func || ex->func->type == ZEND_INTERNAL_FUNCTION
|| !ZEND_OBSERVABLE_FN(ex->func->common.fn_flags)
|| !&RUN_TIME_CACHE(&ex->func->op_array)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought alternatively to make sure the dummy execute_data created in call_attribute_constructor (ext/reflection/php_refleciton.c) should do what zend_get_call_trampoline_func does, but we didn't manage to replicate this:

ZEND_MAP_PTR_INIT(func->run_time_cache, (void***)&dummy);

|| !ZEND_OBSERVER_DATA(&ex->func->op_array)
|| ZEND_OBSERVER_DATA(&ex->func->op_array) == ZEND_OBSERVER_NOT_OBSERVED)) {
ex = ex->prev_execute_data;
Expand Down
27 changes: 27 additions & 0 deletions ext/zend_test/tests/observer_bug81430_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Bug #81430 (Attribute instantiation frame has no run time cache)
--INI--
memory_limit=20M
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
--FILE--
<?php

#[\Attribute]
class A {
public function __construct() {}
}

#[A]
function B() {}

$r = new \ReflectionFunction("B");
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
?>
--EXPECTF--
<!-- init '%s' -->
<file '%s'>
<!-- init A::__construct() -->
<A::__construct>
</A::__construct>
</file '%s'>
33 changes: 33 additions & 0 deletions ext/zend_test/tests/observer_bug81430_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Bug #81430 (Attribute instantiation leaves dangling execute_data pointer)
--INI--
memory_limit=20M
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
--XFAIL--
The stack allocated execute_data is invalid in zend_observer_fcall_end_all
--FILE--
<?php

#[\Attribute]
class A {
public function __construct() {
array_map("str_repeat", ["\xFF"], [100000000]); // cause a bailout
}
}

#[A]
function B() {}

$r = new \ReflectionFunction("B");
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
?>
--EXPECTF--
<!-- init '%s' -->
<file '%s'>
<!-- init A::__construct() -->
<A::__construct>

Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
</A::__construct>
</file '%s'>