Skip to content

Commit 7934a0f

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix missing readonly modification error with inc/dec in JIT
2 parents 6033679 + df93146 commit 7934a0f

10 files changed

+236
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ PHP NEWS
6262

6363
- Opcache:
6464
. Fix incorrect page_size check. (nielsdos)
65+
. Fix readonly modification check when using inc/dec operators on readonly
66+
property with JIT. (ilutov)
6567

6668
- OpenSSL:
6769
. Fixed php_openssl_set_server_dh_param() DH params errors handling. (nielsdos)

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,13 @@ static ZEND_COLD zend_long _zend_jit_throw_dec_prop_error(zend_property_info *pr
26502650

26512651
static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26522652
{
2653+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2654+
2655+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2656+
zend_readonly_property_modification_error(prop_info);
2657+
return;
2658+
}
2659+
26532660
zend_execute_data *execute_data = EG(current_execute_data);
26542661
zval tmp;
26552662

@@ -2673,6 +2680,13 @@ static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_i
26732680

26742681
static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info)
26752682
{
2683+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2684+
2685+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2686+
zend_readonly_property_modification_error(prop_info);
2687+
return;
2688+
}
2689+
26762690
zend_execute_data *execute_data = EG(current_execute_data);
26772691
zval tmp;
26782692

@@ -2710,6 +2724,16 @@ static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_proper
27102724

27112725
static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27122726
{
2727+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2728+
2729+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2730+
zend_readonly_property_modification_error(prop_info);
2731+
if (result) {
2732+
ZVAL_UNDEF(result);
2733+
}
2734+
return;
2735+
}
2736+
27132737
zend_execute_data *execute_data = EG(current_execute_data);
27142738

27152739
ZVAL_DEREF(var_ptr);
@@ -2731,6 +2755,16 @@ static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_prope
27312755

27322756
static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
27332757
{
2758+
ZEND_ASSERT(Z_TYPE_P(var_ptr) != IS_UNDEF);
2759+
2760+
if (UNEXPECTED((prop_info->flags & ZEND_ACC_READONLY))) {
2761+
zend_readonly_property_modification_error(prop_info);
2762+
if (result) {
2763+
ZVAL_UNDEF(result);
2764+
}
2765+
return;
2766+
}
2767+
27342768
zend_execute_data *execute_data = EG(current_execute_data);
27352769

27362770
ZVAL_DEREF(var_ptr);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-inc
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
$this->bar++;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-inc
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
++$this->bar;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump($this->bar++);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump(++$this->bar);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification post-dec
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
$this->bar--;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-dec
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
--$this->bar;
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification dec-inc with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump($this->bar--);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT readonly modification pre-dec with result
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
--FILE--
8+
<?php
9+
class Foo {
10+
public readonly int $bar;
11+
12+
public function __construct() {
13+
$this->bar = 1;
14+
var_dump(--$this->bar);
15+
}
16+
}
17+
18+
new Foo();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$bar in %s:%d
22+
Stack trace:
23+
#0 %s(%d): Foo->__construct()
24+
#1 {main}
25+
thrown in %s on line %d

0 commit comments

Comments
 (0)