Browse Source
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
Fix GH-19701: Serialize/deserialize loses some data
pull/19838/head
Niels Dossche
1 month ago
No known key found for this signature in database
GPG Key ID: B8A8AD166DF0E2E5
3 changed files with
32 additions and
8 deletions
-
NEWS
-
ext/standard/tests/serialize/gh19701.phpt
-
ext/standard/var.c
|
|
@ -16,6 +16,7 @@ PHP NEWS |
|
|
|
- Standard: |
|
|
|
. Fixed bug GH-12265 (Cloning an object breaks serialization recursion). |
|
|
|
(nielsdos) |
|
|
|
. Fixed bug GH-19701 (Serialize/deserialize loses some data). (nielsdos) |
|
|
|
|
|
|
|
- Zip: |
|
|
|
. Fixed bug GH-19688 (Remove pattern overflow in zip addGlob()). (nielsdos) |
|
|
|
|
|
@ -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, |
|
|
|
* since we already wrote the length of the array before */ |
|
|
|
if (Z_TYPE_P(data) == IS_ARRAY) { |
|
|
|
if (UNEXPECTED(Z_IS_RECURSIVE_P(data)) |
|
|
|
|| UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) { |
|
|
|
if (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); |
|
|
|
smart_str_appendl(buf, "N;", 2); |
|
|
|
} else { |
|
|
|
if (Z_REFCOUNTED_P(data)) { |
|
|
|
Z_PROTECT_RECURSION_P(data); |
|
|
|
} |
|
|
|
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false); |
|
|
|
if (Z_REFCOUNTED_P(data)) { |
|
|
|
Z_UNPROTECT_RECURSION_P(data); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
php_var_serialize_intern(buf, data, var_hash, in_rcn_array, false); |
|
|
|