Skip to content

Commit b08aac0

Browse files
committed
Fix inference for assignment of known object to reference
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.
1 parent 1762a87 commit b08aac0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Assigning an object of known type to a reference variable
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $x = 42;
8+
}
9+
10+
function test() {
11+
$r =& $o;
12+
$o = new Test;
13+
$r = new stdClass;
14+
$r->x = 3.141;
15+
var_dump(is_float($o->x));
16+
}
17+
test();
18+
19+
?>
20+
--EXPECT--
21+
bool(true)

ext/opcache/Optimizer/zend_inference.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,11 @@ static zend_always_inline int _zend_update_type_info(
27402740
tmp |= MAY_BE_DOUBLE;
27412741
}
27422742
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2743-
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
2743+
if (tmp & MAY_BE_REF) {
2744+
UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_op->op1_def);
2745+
} else {
2746+
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
2747+
}
27442748
}
27452749
if (ssa_op->result_def >= 0) {
27462750
if (tmp & MAY_BE_REF) {

0 commit comments

Comments
 (0)