Skip to content

Commit be85896

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-15652: Segmentation fault in the Zend engine when JIT enabled (#15717)
2 parents d7febab + 1e78cf9 commit be85896

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,16 @@ static zend_property_info* zend_get_known_property_info(const zend_op_array *op_
696696
return NULL;
697697
}
698698

699-
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, zend_string *filename)
699+
static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *member, bool on_this, const zend_op_array *op_array)
700700
{
701701
zend_property_info *info;
702702

703-
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT)) {
703+
if (!ce || (ce->ce_flags & ZEND_ACC_TRAIT) || (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
704704
return 1;
705705
}
706706

707707
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
708-
if (ce->info.user.filename != filename) {
708+
if (ce->info.user.filename != op_array->filename) {
709709
/* class declaration might be changed independently */
710710
return 1;
711711
}

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12226,7 +12226,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1222612226
| cmp REG2, TMP1
1222712227
| bne >5
1222812228
| MEM_ACCESS_64_WITH_UOFFSET ldr, REG0, REG0, ((opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*)), TMP1
12229-
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array->filename);
12229+
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array);
1223012230
if (may_be_dynamic) {
1223112231
| tst REG0, REG0
1223212232
if (opline->opcode == ZEND_FETCH_OBJ_W) {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12994,7 +12994,7 @@ static int zend_jit_fetch_obj(dasm_State **Dst,
1299412994
| cmp r2, aword [FCARG1a + offsetof(zend_object, ce)]
1299512995
| jne >5
1299612996
| mov r0, aword [r0 + (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*)]
12997-
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array->filename);
12997+
may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array);
1299812998
if (may_be_dynamic) {
1299912999
| test r0, r0
1300013000
if (opline->opcode == ZEND_FETCH_OBJ_W) {

ext/opcache/tests/jit/gh15652.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
JIT: FETCH_OBJ 007
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.jit_hot_func=2
9+
--FILE--
10+
<?php
11+
class C {}
12+
13+
trait T {
14+
public function equal(C $type): bool {
15+
return $type instanceof self && $this->value === $type->value;
16+
}
17+
}
18+
19+
class C1 extends C {
20+
use T;
21+
public function __construct(private int $value) {}
22+
}
23+
24+
class C2 extends C {
25+
use T;
26+
}
27+
28+
$x = new C1(1);
29+
var_dump($x->equal($x));
30+
var_dump($x->equal($x));
31+
$a = new C2("aaa");
32+
var_dump($a->equal($a));
33+
var_dump($a->equal($a));
34+
--EXPECTF--
35+
bool(true)
36+
bool(true)
37+
38+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
39+
40+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
41+
bool(true)
42+
43+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
44+
45+
Warning: Undefined property: C2::$value in %sgh15652.php on line 6
46+
bool(true)

0 commit comments

Comments
 (0)