Skip to content

Commit c4f97a1

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix another typed resource issue in unserialization
2 parents b9ee875 + 2d467ab commit c4f97a1

File tree

2 files changed

+33
-3
lines changed

2 files changed

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

ext/standard/var_unserializer.re

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,17 @@ 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 (info && 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);
559+
if (info) {
560+
if (Z_ISREF_P(old_data)) {
561+
/* If the value is overwritten, remove old type source from ref. */
562+
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(old_data), info);
563+
}
564+
565+
if ((*var_hash)->ref_props) {
566+
/* Remove old entry from ref_props table, if it exists. */
567+
zend_hash_index_del(
568+
(*var_hash)->ref_props, (zend_uintptr_t) old_data);
569+
}
562570
}
563571
var_push_dtor(var_hash, old_data);
564572
Z_TRY_DELREF_P(old_data);

0 commit comments

Comments
 (0)