mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-19701: Serialize/deserialize loses some data
This commit is contained in:
30
ext/standard/tests/serialize/gh19701.phpt
Normal file
30
ext/standard/tests/serialize/gh19701.phpt
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
--TEST--
|
||||||
|
GH-19701 (Serialize/deserialize loses some data)
|
||||||
|
--CREDITS--
|
||||||
|
cuchac
|
||||||
|
DanielEScherzer
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Item {
|
||||||
|
public $children = [];
|
||||||
|
public $parent = null;
|
||||||
|
|
||||||
|
public function __sleep() {
|
||||||
|
return ["children", "parent"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseProduct = new Item();
|
||||||
|
|
||||||
|
$child = new Item();
|
||||||
|
$child->parent = $baseProduct;
|
||||||
|
$baseProduct->children = [ $child ];
|
||||||
|
|
||||||
|
$data = [clone $baseProduct, $baseProduct];
|
||||||
|
|
||||||
|
echo serialize($data), "\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
a:2:{i:0;O:4:"Item":2:{s:8:"children";a:1:{i:0;O:4:"Item":2:{s:8:"children";a:0:{}s:6:"parent";O:4:"Item":2:{s:8:"children";a:1:{i:0;r:4;}s:6:"parent";N;}}}s:6:"parent";N;}i:1;r:6;}
|
||||||
@@ -1001,18 +1001,11 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable
|
|||||||
/* we should still add element even if it's not OK,
|
/* we should still add element even if it's not OK,
|
||||||
* since we already wrote the length of the array before */
|
* since we already wrote the length of the array before */
|
||||||
if (Z_TYPE_P(data) == IS_ARRAY) {
|
if (Z_TYPE_P(data) == IS_ARRAY) {
|
||||||
if (UNEXPECTED(Z_IS_RECURSIVE_P(data))
|
if (UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) {
|
||||||
|| UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) {
|
|
||||||
php_add_var_hash(var_hash, struc, in_rcn_array);
|
php_add_var_hash(var_hash, struc, in_rcn_array);
|
||||||
smart_str_appendl(buf, "N;", 2);
|
smart_str_appendl(buf, "N;", 2);
|
||||||
} else {
|
} else {
|
||||||
if (Z_REFCOUNTED_P(data)) {
|
|
||||||
Z_PROTECT_RECURSION_P(data);
|
|
||||||
}
|
|
||||||
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false);
|
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false);
|
||||||
if (Z_REFCOUNTED_P(data)) {
|
|
||||||
Z_UNPROTECT_RECURSION_P(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false);
|
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user