Skip to content

Commit 32c919b

Browse files
committed
Handle references after FETCH_OBJ_R with REG destination
zend_jit_fetch_obj_r_slow_ex() may be used by the function JIT, which doesn't rely on guards to handle references. Therefore it must deref the property value. Other variants of zend_jit_fetch_obj_*_slow_ex can not be used used in function JIT. Fixes phpGH-19831 Closes phpGH-19838
1 parent 74cacdd commit 32c919b

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ PHP NEWS
3030
- Opcache:
3131
. Fixed bug GH-19669 (assertion failure in zend_jit_trace_type_to_info_ex).
3232
(Arnaud)
33+
. Fixed bug GH-19831 (function JIT may not deref property value). (Arnaud)
3334

3435
- Soap:
3536
. Fixed bug GH-19784 (SoapServer memory leak). (nielsdos)

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,8 +1965,13 @@ static zval* ZEND_FASTCALL zend_jit_fetch_obj_r_slow_ex(zend_object *zobj)
19651965
void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS);
19661966

19671967
retval = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, result);
1968-
if (retval == result && UNEXPECTED(Z_ISREF_P(retval))) {
1969-
zend_unwrap_reference(retval);
1968+
if (UNEXPECTED(Z_ISREF_P(retval))) {
1969+
if (retval == result) {
1970+
zend_unwrap_reference(retval);
1971+
} else {
1972+
retval = Z_REFVAL_P(retval);
1973+
}
1974+
ZEND_ASSERT(!Z_REFCOUNTED_P(retval));
19701975
}
19711976
return retval;
19721977
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
GH-19831 001: fetch obj slow R REG + reference
3+
--CREDITS--
4+
dktapps
5+
--ENV--
6+
RT_COND=1
7+
--INI--
8+
opcache.jit=1203
9+
--FILE--
10+
<?php
11+
12+
if (getenv('RT_COND')) {
13+
class Base {
14+
}
15+
}
16+
17+
// Class is not linked
18+
class Test extends Base {
19+
public int $layers = 1;
20+
21+
public function getLayers(): int {
22+
// Prop info is not known, but res_addr is REG
23+
return $this->layers;
24+
}
25+
}
26+
27+
$t = new Test();
28+
$a = &$t->layers;
29+
var_dump($t->getLayers());
30+
31+
?>
32+
--EXPECT--
33+
int(1)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-19831 002: fetch obj slow R REG + __get + reference
3+
--CREDITS--
4+
dktapps
5+
--ENV--
6+
RT_COND=1
7+
--INI--
8+
opcache.jit=1203
9+
--FILE--
10+
<?php
11+
12+
if (getenv('RT_COND')) {
13+
class Base {
14+
}
15+
}
16+
17+
// Class is not linked
18+
class Test extends Base {
19+
public int $layers = 1;
20+
21+
public function &__get($name) {
22+
global $a;
23+
$a = 1;
24+
return $a;
25+
}
26+
27+
public function getLayers(): int {
28+
// Prop info is not known, but res_addr is REG
29+
return $this->layers;
30+
}
31+
}
32+
33+
$t = new Test();
34+
unset($t->layers);
35+
var_dump($t->getLayers());
36+
37+
?>
38+
--EXPECT--
39+
int(1)

0 commit comments

Comments
 (0)