Skip to content
Open
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
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ PHP NEWS
. Fix stmt->query leak in mysqli_execute_query() validation errors.
(David Carlier)

- Opcache:
. Fixed bug GH-22158 (Tracing JIT dispatches the observer begin handler
through the wrong run_time_cache slot on megamorphic calls). (ptondereau,
iliaal)

- Phar:
. Fixed a bypass of the magic ".phar" directory protection in
Phar::addEmptyDir() for paths starting with "/.phar", while allowing
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4815,7 +4815,7 @@ static struct jit_observer_fcall_is_unobserved_data jit_observer_fcall_is_unobse
ir_ref observer_handler_user = ir_ADD_OFFSET(run_time_cache, zend_observer_fcall_op_array_extension * sizeof(void *));

ir_MERGE_WITH(if_internal_func_end);
*observer_handler = ir_PHI_2(IR_ADDR, observer_handler_internal, observer_handler_user);
*observer_handler = ir_PHI_2(IR_ADDR, observer_handler_user, observer_handler_internal);
}

// JIT: if (*observer_handler == ZEND_OBSERVER_NONE_OBSERVED) {
Expand Down
33 changes: 33 additions & 0 deletions ext/opcache/tests/jit/gh22158.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-22158 (Tracing JIT dispatches observer begin handler through the wrong run_time_cache slot on megamorphic calls)
--EXTENSIONS--
opcache
zend_test
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=tracing
opcache.jit_buffer_size=32M
opcache.jit_max_polymorphic_calls=0
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
zend_test.observer.show_output=0
zend_test.observer.reserve_op_array_handle=1
--FILE--
<?php
interface S { public function f(): int; }
final class A implements S { public function f(): int { return 1; } }
final class B implements S { public function f(): int { return 2; } }
final class C implements S { public function f(): int { return 3; } }
final class D implements S { public function f(): int { return 4; } }
final class E implements S { public function f(): int { return 5; } }

$o = [new A, new B, new C, new D, new E];
$t = 0;
for ($i = 0; $i < 200000; $i++) {
$t += $o[$i % 5]->f();
}
echo $t, "\n";
?>
--EXPECT--
600000
5 changes: 5 additions & 0 deletions ext/zend_test/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "php_test.h"
#include "observer.h"
#include "zend_observer.h"
#include "zend_extensions.h"
#include "zend_smart_str.h"
#include "ext/standard/php_var.h"
#include "zend_generators.h"
Expand Down Expand Up @@ -378,6 +379,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("zend_test.observer.fiber_switch", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_fiber_switch, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.fiber_destroy", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_fiber_destroy, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.execute_internal", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_execute_internal, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.observer.reserve_op_array_handle", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_reserve_op_array_handle, zend_zend_test_globals, zend_test_globals)
PHP_INI_END()

void zend_test_observer_init(INIT_FUNC_ARGS)
Expand All @@ -386,6 +388,9 @@ void zend_test_observer_init(INIT_FUNC_ARGS)
if (type != MODULE_TEMPORARY) {
REGISTER_INI_ENTRIES();
if (ZT_G(observer_enabled)) {
if (ZT_G(observer_reserve_op_array_handle)) {
zend_get_op_array_extension_handle("zend_test");
}
zend_observer_fcall_register(observer_fcall_init);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions ext/zend_test/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
int observer_fiber_switch;
int observer_fiber_destroy;
int observer_execute_internal;
int observer_reserve_op_array_handle;
HashTable *global_weakmap;
int replace_zend_execute_ex;
int register_passes;
Expand Down
Loading