Skip to content

Fix GH-13712: Segmentation fault for enabled observers when calling trait method of internal trait when opcache is loaded #13735

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

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ PHP NEWS
- Opcache:
. Fixed GH-13508 (JITed QM_ASSIGN may be optimized out when op1 is null).
(Arnaud, Dmitry)
. Fixed GH-13712 (Segmentation fault for enabled observers when calling trait
method of internal trait when opcache is loaded). (Bob)

- PDO:
. Fix various PDORow bugs. (Girgias)
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,9 +1917,9 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
} else {
new_fn = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
memcpy(new_fn, fn, sizeof(zend_op_array));
new_fn->op_array.fn_flags |= ZEND_ACC_TRAIT_CLONE;
new_fn->op_array.fn_flags &= ~ZEND_ACC_IMMUTABLE;
}
new_fn->common.fn_flags |= ZEND_ACC_TRAIT_CLONE;
Comment on lines -1920 to +1922
Copy link
Member

Choose a reason for hiding this comment

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

This looks right.


/* Reassign method name, in case it is an alias. */
new_fn->common.function_name = name;
Expand Down
23 changes: 23 additions & 0 deletions ext/opcache/tests/gh13712.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-13712 (Segmentation fault for enabled observers when calling trait method of internal trait when opcache is loaded)
--EXTENSIONS--
opcache
zend_test
--INI--
zend_test.observer.enabled=1
opcache.enable=1
opcache.enable_cli=1
--FILE--
<?php
class Foo {
use _ZendTestTrait;
}

$f = new Foo();
var_dump($f->testMethod());
?>
--EXPECTF--
<!-- init '%s' -->
<!-- init Foo::testMethod() -->
<!-- init var_dump() -->
bool(true)
2 changes: 1 addition & 1 deletion ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ static void zend_persist_class_method(zval *zv, zend_class_entry *ce)
}
// Real dynamically created internal functions like enum methods must have their own run_time_cache pointer. They're always on the same scope as their defining class.
// However, copies - as caused by inheritance of internal methods - must retain the original run_time_cache pointer, shared with the source function.
if (!op_array->scope || op_array->scope == ce) {
if (!op_array->scope || (op_array->scope == ce && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE))) {
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
Comment on lines -729 to 730
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this.
I don't know why do we need run-time cache for internal functions and how it should behave in case of inheritance.

Copy link
Member

Choose a reason for hiding this comment

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

Internal functions use the run time cache to cache installed observers.

}
}
Expand Down