Skip to content

Commit fe320e8

Browse files
committed
Tracing JIT: Fix reference counting
Fixes oss-fuzz #42225
1 parent cbc0b1a commit fe320e8

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11865,7 +11865,7 @@ static int zend_jit_zval_copy_deref(dasm_State **Dst, zend_jit_addr res_addr, ze
1186511865
return 1;
1186611866
}
1186711867

11868-
static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline)
11868+
static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline, uint32_t op1_info)
1186911869
{
1187011870
switch (opline->opcode) {
1187111871
case ZEND_FETCH_OBJ_FUNC_ARG:
@@ -11877,7 +11877,8 @@ static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline)
1187711877
/* break missing intentionally */
1187811878
case ZEND_FETCH_OBJ_R:
1187911879
case ZEND_FETCH_OBJ_IS:
11880-
if (opline->op2_type == IS_CONST
11880+
if ((op1_info & MAY_BE_OBJECT)
11881+
&& opline->op2_type == IS_CONST
1188111882
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_STRING
1188211883
&& Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))[0] != '\0') {
1188311884
return 1;
@@ -11956,7 +11957,7 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst,
1195611957
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1195711958
&& (ssa_op+1)->op1_use == ssa_op->result_def
1195811959
&& !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG)))
11959-
&& zend_jit_may_avoid_refcounting(opline+1)) {
11960+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1196011961
result_avoid_refcounting = 1;
1196111962
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1196211963
}
@@ -13225,7 +13226,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1322513226
&& !(flags & ZEND_JIT_EXIT_FREE_OP1)
1322613227
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
1322713228
&& (ssa_op+1)->op1_use == ssa_op->result_def
13228-
&& zend_jit_may_avoid_refcounting(opline+1)) {
13229+
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
1322913230
result_avoid_refcounting = 1;
1323013231
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
1323113232
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
JIT: FETCH_OBJ 008
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 A {
11+
public string $prop = "";
12+
}
13+
14+
class B {
15+
public function __toString() {
16+
global $a;
17+
$a->prop = "A $e B";
18+
$a->prop->prop . $a->prop = "C";
19+
return "test";
20+
}
21+
}
22+
23+
$a = new A;
24+
$a->prop = new B;
25+
?>
26+
DONE
27+
--EXPECTF--
28+
Warning: Undefined variable $e in %sfetch_obj_008.php on line 9
29+
30+
Warning: Attempt to read property "prop" on string in %sfetch_obj_008.php on line 10
31+
DONE

0 commit comments

Comments
 (0)