[php-src] PR #21710: Fix GH-21368 crash: runtime orig_handler lookup in escape_if_undef
| From: | iliaal | Date: | Fri, 10 Apr 2026 12:42:44 +0000 |
| Subject: | [php-src] PR #21710: Fix GH-21368 crash: runtime orig_handler lookup in escape_if_undef | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35659@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21710
Author: iliaal
Follow-up to #21368.
@vibbow reported an access violation in
zend_jit_escape_if_undef on PHP 8.5.5 VS17 x64
NTS (Windows + IIS + FastCGI), crashing at the fix I introduced in #21368:
```
FAILURE_BUCKET_ID: INVALID_POINTER_READ_c0000005_php8.dll!zend_jit_escape_if_undef
FAULTING_SOURCE_LINE_NUMBER: 7980
```
The crashing instruction is mov rcx, [rax+rcx*8+0xD0], where rax is a heap
address and the byte at +0xD0 is unmapped. On 64-bit NTS that offset matches
zend_op_array->reserved[zend_func_info_rid], which is exactly what
ZEND_FUNC_INFO(op_array) expands to in my fix.
## Root cause
#21368 changed zend_jit_escape_if_undef to dispatch directly to
orig_handler, computed at JIT compile time from exit_info->op_array.
That pointer is unreliable:
- zend_jit_trace_get_exit_point sets op_array = NULL at
ext/opcache/jit/zend_jit_trace.c:164 when JIT_G(current_frame) is NULL at
exit-point creation.
- Even when non-NULL, the op_array can be freed between exit-point creation and side-trace
compilation. The crash's read address at +0xD0 lands in released memory, which
fits a freed/reused op_array.
Either way, ZEND_FUNC_INFO(op_array) dereferences a bad pointer.
## Fix
Use the existing zend_jit_orig_opline_handler(jit) runtime helper instead. It emits IR
that loads EX(func)->reserved[rid]->offset at dispatch time, adds it to the
current IP, and loads orig_handler. EX(func) is the currently-executing
frame's function, so no compile-time op_array is needed.
zend_jit_trace_exit_stub already uses this exact pattern at
zend_jit_ir.c:2525.
I dropped the op_array parameter from zend_jit_escape_if_undef and updated
the call site in zend_jit_trace_deoptimization.
## Verification
gh21267.phpt and gh21267_blacklist.phpt both still pass, confirming the
original infinite-loop fix is preserved.
## Reproducer
I tried to build a native Linux reproducer and couldn't trigger the NULL/stale
op_array path through synthetic stress, opcache invalidation, or trace-buffer
manipulation. The race looks specific to long-running FastCGI workers on Windows where opcache
eviction crosses with side-trace compilation. The crash dump analysis is unambiguous and the
runtime-lookup fix eliminates the class of issue.