Skip to content

Commit 8c2cc0e

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix another ref source management bug in unserialize
2 parents de7f3f0 + ed9532c commit 8c2cc0e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Overwriting a typed property reference
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public ?object $prop;
8+
}
9+
$s = <<<'STR'
10+
O:4:"Test":2:{s:4:"prop";R:1;s:4:"prop";N;}}
11+
STR;
12+
var_dump(unserialize($s));
13+
14+
?>
15+
--EXPECT--
16+
object(Test)#1 (1) {
17+
["prop"]=>
18+
NULL
19+
}

ext/standard/var_unserializer.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ string_key:
556556
/* This is a property with a declaration */
557557
old_data = Z_INDIRECT_P(old_data);
558558
info = zend_get_typed_property_info_for_slot(obj, old_data);
559+
if (Z_ISREF_P(old_data)) {
560+
/* If the value is overwritten, remove old type source from ref. */
561+
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(old_data), info);
562+
}
559563
var_push_dtor(var_hash, old_data);
560564
Z_TRY_DELREF_P(old_data);
561565
ZVAL_COPY_VALUE(old_data, &d);

0 commit comments

Comments
 (0)