Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
serialize(): a by-reference __serialize() that grows the array being walked must not free it
--FILE--
<?php
class G {
public $ref;
public function __serialize(): array {
for ($i = 0; $i < 128; $i++) {
$this->ref[] = 'x' . $i;
}
return ['d' => 1];
}
}
$g = new G();
$inner = [$g, 'tail'];
$g->ref = &$inner;
$top = [&$inner];
var_dump(serialize($top));
?>
--EXPECT--
string(59) "a:1:{i:0;a:2:{i:0;O:1:"G":1:{s:1:"d";i:1;}i:1;s:4:"tail";}}"
8 changes: 6 additions & 2 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,13 +1303,17 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
zend_release_properties(myht);
return;
}
case IS_ARRAY:
case IS_ARRAY: {
smart_str_appendl(buf, "a:", 2);
myht = Z_ARRVAL_P(struc);
bool rcn = !is_root && (in_rcn_array || GC_REFCOUNT(myht) > 1);
GC_TRY_ADDREF(myht);
php_var_serialize_nested_data(
buf, struc, myht, zend_array_count(myht), /* incomplete_class */ false, var_hash,
!is_root && (in_rcn_array || GC_REFCOUNT(myht) > 1));
rcn);
GC_TRY_DTOR_NO_REF(myht);
return;
}
case IS_REFERENCE:
struc = Z_REFVAL_P(struc);
goto again;
Expand Down
Loading