Skip to content

Commit

Permalink
Tracing JIT: Fix reference counting
Browse files Browse the repository at this point in the history
Fixes oss-fuzz #42225
  • Loading branch information
dstogov committed Dec 13, 2021
1 parent cbc0b1a commit fe320e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ext/opcache/jit/zend_jit_x86.dasc
Expand Up @@ -11865,7 +11865,7 @@ static int zend_jit_zval_copy_deref(dasm_State **Dst, zend_jit_addr res_addr, ze
return 1;
}

static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline)
static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline, uint32_t op1_info)
{
switch (opline->opcode) {
case ZEND_FETCH_OBJ_FUNC_ARG:
Expand All @@ -11877,7 +11877,8 @@ static zend_bool zend_jit_may_avoid_refcounting(const zend_op *opline)
/* break missing intentionally */
case ZEND_FETCH_OBJ_R:
case ZEND_FETCH_OBJ_IS:
if (opline->op2_type == IS_CONST
if ((op1_info & MAY_BE_OBJECT)
&& opline->op2_type == IS_CONST
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_STRING
&& Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))[0] != '\0') {
return 1;
Expand Down Expand Up @@ -11956,7 +11957,7 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst,
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
&& (ssa_op+1)->op1_use == ssa_op->result_def
&& !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG)))
&& zend_jit_may_avoid_refcounting(opline+1)) {
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
result_avoid_refcounting = 1;
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
}
Expand Down Expand Up @@ -13225,7 +13226,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
&& !(flags & ZEND_JIT_EXIT_FREE_OP1)
&& (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))
&& (ssa_op+1)->op1_use == ssa_op->result_def
&& zend_jit_may_avoid_refcounting(opline+1)) {
&& zend_jit_may_avoid_refcounting(opline+1, res_info)) {
result_avoid_refcounting = 1;
ssa->var_info[ssa_op->result_def].avoid_refcounting = 1;
}
Expand Down
31 changes: 31 additions & 0 deletions ext/opcache/tests/jit/fetch_obj_008.phpt
@@ -0,0 +1,31 @@
--TEST--
JIT: FETCH_OBJ 008
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
class A {
public string $prop = "";
}

class B {
public function __toString() {
global $a;
$a->prop = "A $e B";
$a->prop->prop . $a->prop = "C";
return "test";
}
}

$a = new A;
$a->prop = new B;
?>
DONE
--EXPECTF--
Warning: Undefined variable $e in %sfetch_obj_008.php on line 9

Warning: Attempt to read property "prop" on string in %sfetch_obj_008.php on line 10
DONE

0 comments on commit fe320e8

Please sign in to comment.