Skip to content

Commit 4170d41

Browse files
committed
JIT: Fix incorrect FETCH_THIS elimination
Fizex oss-fuzz #43159
1 parent 2f6a06c commit 4170d41

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,8 +3147,9 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse
31473147
}
31483148
}
31493149

3150-
static zend_bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ssa_opcodes, int var)
3150+
static zend_bool zend_jit_may_delay_fetch_this(const zend_op_array *op_array, zend_ssa *ssa, const zend_op **ssa_opcodes, const zend_ssa_op *ssa_op)
31513151
{
3152+
int var = ssa_op->result_def;
31523153
int i;
31533154
int use = ssa->vars[var].use_chain;
31543155
const zend_op *opline;
@@ -3189,6 +3190,19 @@ static zend_bool zend_jit_may_delay_fetch_this(zend_ssa *ssa, const zend_op **ss
31893190
return 0;
31903191
}
31913192

3193+
if (opline->opcode == ZEND_ASSIGN_OBJ_OP) {
3194+
if (opline->op1_type == IS_CV
3195+
&& (opline+1)->op1_type == IS_CV
3196+
&& (opline+1)->op1.var == opline->op1.var) {
3197+
/* skip $a->prop += $a; */
3198+
return 0;
3199+
}
3200+
if (!zend_jit_supported_binary_op(
3201+
opline->extended_value, MAY_BE_ANY, OP1_DATA_INFO())) {
3202+
return 0;
3203+
}
3204+
}
3205+
31923206
for (i = ssa->vars[var].definition; i < use; i++) {
31933207
if (ssa_opcodes[i]->opcode == ZEND_DO_UCALL
31943208
|| ssa_opcodes[i]->opcode == ZEND_DO_FCALL_BY_NAME
@@ -5610,7 +5624,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
56105624
case ZEND_FETCH_THIS:
56115625
delayed_fetch_this = 0;
56125626
if (ssa_op->result_def >= 0 && opline->result_type != IS_CV) {
5613-
if (zend_jit_may_delay_fetch_this(ssa, ssa_opcodes, ssa_op->result_def)) {
5627+
if (zend_jit_may_delay_fetch_this(op_array, ssa, ssa_opcodes, ssa_op)) {
56145628
ssa->var_info[ssa_op->result_def].delayed_fetch_this = 1;
56155629
delayed_fetch_this = 1;
56165630
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
JIT ASSIGN_OBJ_OP: Unsupported types
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+
class Test{
11+
}
12+
13+
$test = new Test;
14+
(function(){$this->y.=[];})->call($test);
15+
?>
16+
--EXPECTF--
17+
Warning: Undefined property: Test::$y in %sassign_obj_op_001.php on line 6
18+
19+
Warning: Array to string conversion in %sassign_obj_op_001.php on line 6

0 commit comments

Comments
 (0)