Skip to content

Commit ac65f6a

Browse files
committed
Fixed bug #81051 (Broken property type handling after incrementing reference)
1 parent ceb0951 commit ac65f6a

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
. Fixed bug #76359 (open_basedir bypass through adding ".."). (cmb)
1010

1111
- Opcache:
12+
. Fixed bug #81051 (Broken property type handling after incrementing
13+
reference). (Dmitry)
1214
. Fixed bug #80968 (JIT segfault with return from required file). (Dmitry)
1315

1416
- Standard:

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,7 @@ static void ZEND_FASTCALL zend_jit_assign_op_to_typed_prop(zval *zptr, zend_prop
21792179
zend_execute_data *execute_data = EG(current_execute_data);
21802180
zval z_copy;
21812181

2182+
ZVAL_DEREF(zptr);
21822183
binary_op(&z_copy, zptr, value);
21832184
if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
21842185
zval_ptr_dtor(zptr);
@@ -2261,6 +2262,7 @@ static void ZEND_FASTCALL zend_jit_inc_typed_prop(zval *var_ptr, zend_property_i
22612262
zend_execute_data *execute_data = EG(current_execute_data);
22622263
zval tmp;
22632264

2265+
ZVAL_DEREF(var_ptr);
22642266
ZVAL_COPY(&tmp, var_ptr);
22652267

22662268
increment_function(var_ptr);
@@ -2283,6 +2285,7 @@ static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_i
22832285
zend_execute_data *execute_data = EG(current_execute_data);
22842286
zval tmp;
22852287

2288+
ZVAL_DEREF(var_ptr);
22862289
ZVAL_COPY(&tmp, var_ptr);
22872290

22882291
decrement_function(var_ptr);
@@ -2309,6 +2312,7 @@ static void ZEND_FASTCALL zend_jit_pre_inc_typed_prop(zval *var_ptr, zend_proper
23092312
result = &tmp;
23102313
}
23112314

2315+
ZVAL_DEREF(var_ptr);
23122316
ZVAL_COPY(result, var_ptr);
23132317

23142318
increment_function(var_ptr);
@@ -2339,6 +2343,7 @@ static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_proper
23392343
result = &tmp;
23402344
}
23412345

2346+
ZVAL_DEREF(var_ptr);
23422347
ZVAL_COPY(result, var_ptr);
23432348

23442349
decrement_function(var_ptr);
@@ -2364,6 +2369,7 @@ static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_prope
23642369
{
23652370
zend_execute_data *execute_data = EG(current_execute_data);
23662371

2372+
ZVAL_DEREF(var_ptr);
23672373
ZVAL_COPY(result, var_ptr);
23682374

23692375
increment_function(var_ptr);
@@ -2384,6 +2390,7 @@ static void ZEND_FASTCALL zend_jit_post_dec_typed_prop(zval *var_ptr, zend_prope
23842390
{
23852391
zend_execute_data *execute_data = EG(current_execute_data);
23862392

2393+
ZVAL_DEREF(var_ptr);
23872394
ZVAL_COPY(result, var_ptr);
23882395

23892396
decrement_function(var_ptr);

ext/opcache/tests/jit/bug81051.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #80839: PHP problem with JIT
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_buffer_size=1M
7+
opcache.jit=1205
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
class Binary{
13+
public static function readUnsignedVarInt(string $buffer, int &$offset) : int{
14+
$offset++;
15+
return 0;
16+
}
17+
}
18+
19+
class BinaryStream{
20+
21+
private string $buffer;
22+
private int $offset;
23+
24+
public function __construct(string $buffer, int $offset = 0){
25+
$this->buffer = $buffer;
26+
$this->offset = $offset;
27+
}
28+
29+
public function getUnsignedVarInt() : int{
30+
return Binary::readUnsignedVarInt($this->buffer, $this->offset);
31+
}
32+
33+
public function get(int $len) : string{
34+
return $len === 1 ? $this->buffer[$this->offset++] : substr($this->buffer, ($this->offset += $len) - $len, $len);
35+
}
36+
}
37+
$stream = new BinaryStream(str_repeat("\x01a", 1000));
38+
var_dump($stream->getUnsignedVarInt());
39+
var_dump($stream->get(1));
40+
?>
41+
--EXPECT--
42+
int(0)
43+
string(1) "a"

0 commit comments

Comments
 (0)