From 80552d8216c302fee77dd6d7671e5389cd81be2f Mon Sep 17 00:00:00 2001 From: ndossche <7771979+ndossche@users.noreply.github.com> Date: Sun, 22 Nov 2026 15:58:14 +0100 Subject: [PATCH] ext/opcache: Fix JIT register allocation for ASSIGN to traced reference Fixes OSS-Fuzz https://issues.oss-fuzz.com/issues/585402260 Also disable regalloc for ASSIGN when op1 was recorded as a reference. --- ext/opcache/jit/zend_jit_trace.c | 9 +++-- .../tests/jit/assign_typed_ref_reg_001.phpt | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 ext/opcache/tests/jit/assign_typed_ref_reg_001.phpt diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 5f4bd908a5f8..36a0baa8c9ff 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -2934,9 +2934,12 @@ static zend_jit_reg_var* zend_jit_trace_allocate_registers(zend_jit_trace_rec *t if (support_opline && opline->opcode == ZEND_ASSIGN && opline->op1_type == IS_CV - && ssa_op->op1_def >= 0 - && ssa->vars[ssa_op->op1_def].alias != NO_ALIAS) { - /* avoid register allocation in case of possibility of indirect modification*/ + && ((ssa_op->op1_def >= 0 + && ssa->vars[ssa_op->op1_def].alias != NO_ALIAS) + || (p->op1_type != IS_UNKNOWN + && (p->op1_type & IS_TRACE_REFERENCE)))) { + /* avoid register allocation in case of possibility of indirect modification + * or assignment through a (possibly typed) reference */ support_opline = 0; } diff --git a/ext/opcache/tests/jit/assign_typed_ref_reg_001.phpt b/ext/opcache/tests/jit/assign_typed_ref_reg_001.phpt new file mode 100644 index 000000000000..b33040e13208 --- /dev/null +++ b/ext/opcache/tests/jit/assign_typed_ref_reg_001.phpt @@ -0,0 +1,36 @@ +--TEST-- +JIT ASSIGN: result must not be register-allocated when op1 is traced as a reference +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=tracing +opcache.jit_buffer_size=64M +opcache.jit_hot_loop=1 +opcache.jit_hot_side_exit=1 +--EXTENSIONS-- +opcache +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECTF-- +Warning: Undefined variable $x in %s on line %d + +Warning: Undefined variable $a in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +TypeError: Unsupported operand types: string + string