Skip to content

Commit

Permalink
Fix inference for assignment of known object to reference
Browse files Browse the repository at this point in the history
We cannot retain the ce information in that case, we have to
assume the ce may change indirectly through the reference.

Fixes oss-fuzz #46720.
  • Loading branch information
nikic committed Apr 15, 2022
1 parent 1762a87 commit b08aac0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Zend/tests/assign_obj_to_ref_inference.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Assigning an object of known type to a reference variable
--FILE--
<?php

class Test {
public int $x = 42;
}

function test() {
$r =& $o;
$o = new Test;
$r = new stdClass;
$r->x = 3.141;
var_dump(is_float($o->x));
}
test();

?>
--EXPECT--
bool(true)
6 changes: 5 additions & 1 deletion ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,11 @@ static zend_always_inline int _zend_update_type_info(
tmp |= MAY_BE_DOUBLE;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
if (tmp & MAY_BE_REF) {
UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_op->op1_def);
} else {
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
}
}
if (ssa_op->result_def >= 0) {
if (tmp & MAY_BE_REF) {
Expand Down

0 comments on commit b08aac0

Please sign in to comment.