Skip to content

Commit 69c10ae

Browse files
committed
Fix incorrect guard motion out of the loop
Fixes oss-fuzz #49579
1 parent 4b19b85 commit 69c10ae

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

+11
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,17 @@ static int is_checked_guard(const zend_ssa *tssa, const zend_op **ssa_opcodes, u
10951095
&& (tssa->var_info[tssa->ops[idx].op2_use].type & MAY_BE_REF)) {
10961096
return 0;
10971097
}
1098+
if (!(tssa->var_info[tssa->ops[idx].op1_use].type & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
1099+
return 0;
1100+
}
1101+
if (opline->op2_type == IS_CONST) {
1102+
zval *zv = RT_CONSTANT(opline, opline->op2);
1103+
if (Z_TYPE_P(zv) != IS_LONG && Z_TYPE_P(zv) != IS_DOUBLE) {
1104+
return 0;
1105+
}
1106+
} else if (!(tssa->var_info[tssa->ops[idx].op2_use].type & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
1107+
return 0;
1108+
}
10981109
return 1;
10991110
}
11001111
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
JIT ASSIGN_OP: 009 incorrect guard motion out of the loop
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 foo() {
11+
$x = $a = $c = 0;
12+
for($cnt=0;$cnt<6;$cnt++) {
13+
$a *= $a;
14+
for ($i = 0; $i <= .1; !$j++)
15+
for ($i = 0; $i <= .1; !$i++)
16+
for ($i = 0; $i << .1; !$i++);
17+
$x != $a ?: $c;
18+
$a = "3566715245541";
19+
}
20+
}
21+
@foo();
22+
@foo();
23+
@foo();
24+
?>
25+
DONE
26+
--EXPECT--
27+
DONE

0 commit comments

Comments
 (0)