Skip to content

Commit 77325c4

Browse files
committed
Fix removal of type source during unserialization
Missed a check for info in this code. Add it, and add an assertion in type source removal to make it easier to catch this issue. Fixes oss-fuzz #28208 and #28257.
1 parent 426fe2f commit 77325c4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Zend/zend_execute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,7 @@ ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_l
32623262
zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
32633263
zend_property_info **ptr, **end;
32643264

3265+
ZEND_ASSERT(prop);
32653266
if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) {
32663267
ZEND_ASSERT(source_list->ptr == prop);
32673268
source_list->ptr = NULL;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Overwrite reference in untyped property
3+
--FILE--
4+
<?php
5+
class Test {
6+
public $prop;
7+
}
8+
$s = <<<'STR'
9+
O:4:"Test":2:{s:4:"prop";R:1;s:4:"prop";i:0;}
10+
STR;
11+
var_dump(unserialize($s));
12+
?>
13+
--EXPECT--
14+
object(Test)#1 (1) {
15+
["prop"]=>
16+
int(0)
17+
}

ext/standard/var_unserializer.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ 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)) {
559+
if (info && Z_ISREF_P(old_data)) {
560560
/* If the value is overwritten, remove old type source from ref. */
561561
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(old_data), info);
562562
}

0 commit comments

Comments
 (0)