Skip to content

Commit 478448d

Browse files
committed
JIT: Fix register alloction (missed store)
Fixes oss-fuzz #44242
1 parent a60a9b4 commit 478448d

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

ext/opcache/jit/zend_jit_trace.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -3826,7 +3826,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
38263826

38273827
ssa->var_info[i].type &= ~MAY_BE_GUARD;
38283828
op_type = concrete_type(ssa->var_info[i].type);
3829-
if (!zend_jit_type_guard(&dasm_state, opline, i, op_type)) {
3829+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(i), op_type)) {
38303830
goto jit_failure;
38313831
}
38323832
SET_STACK_TYPE(stack, i, op_type, 1);
@@ -3859,7 +3859,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
38593859
ZEND_ASSERT(ival->reg != ZREG_NONE);
38603860

38613861
if (info & MAY_BE_GUARD) {
3862-
if (!zend_jit_type_guard(&dasm_state, opline, phi->var, concrete_type(info))) {
3862+
if (!zend_jit_type_guard(&dasm_state, opline, EX_NUM_TO_VAR(phi->var), concrete_type(info))) {
38633863
goto jit_failure;
38643864
}
38653865
info &= ~MAY_BE_GUARD;
@@ -5986,8 +5986,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
59865986
|| opline->opcode == ZEND_COALESCE
59875987
|| opline->opcode == ZEND_JMP_NULL
59885988
|| opline->opcode == ZEND_FE_RESET_R) {
5989-
if (!ra[ssa_op->op1_use]
5990-
|| ra[ssa_op->op1_use]->reg != ra[ssa_op->op1_def]->reg) {
5989+
if (!ra[ssa_op->op1_use]) {
59915990
flags |= ZREG_LOAD;
59925991
}
59935992
}

ext/opcache/jit/zend_jit_x86.dasc

+12
Original file line numberDiff line numberDiff line change
@@ -3922,6 +3922,18 @@ static int zend_jit_update_regs(dasm_State **Dst, uint32_t var, zend_jit_addr sr
39223922
} else {
39233923
ZEND_UNREACHABLE();
39243924
}
3925+
if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) {
3926+
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var);
3927+
3928+
if (!zend_jit_spill_store(Dst, dst, var_addr, info,
3929+
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
3930+
JIT_G(current_frame) == NULL ||
3931+
STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN ||
3932+
(1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY)
3933+
)) {
3934+
return 0;
3935+
}
3936+
}
39253937
} else if (Z_MODE(dst) == IS_MEM_ZVAL) {
39263938
if (!Z_LOAD(src) && !Z_STORE(src)) {
39273939
if (!zend_jit_spill_store(Dst, src, dst, info,
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Register Alloction 007: Missing store
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function test() {
11+
for ($i = 0; $i < 100; $i++) {
12+
$a = $a + $a = $a + !$a = $a;
13+
$aZ = $a;
14+
$aZ %= $a;
15+
}
16+
}
17+
test();
18+
?>
19+
--EXPECTF--
20+
Warning: Undefined variable $a in %sreg_alloc_007.php on line 4
21+
22+
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in %sreg_alloc_007.php:6
23+
Stack trace:
24+
#0 %sreg_alloc_007.php(9): test()
25+
#1 {main}
26+
thrown in %sreg_alloc_007.php on line 6

0 commit comments

Comments
 (0)