Skip to content

Commit 0d99628

Browse files
committed
Fix edge case serializing __PHP_Incomplete_Class properties.
This was using strcmp instead of zend_string_equals_literal. As a result, the property count didn't match the number of properties being serialized if properties started with "__PHP_Incomplete_Class\0" (unlikely) (before, `'O:8:"Missing_":1:{}'` would be serialized, which failed to unserialize) Everywhere else expects the MAGIC_MEMBER to match exactly, and this should use zend_string_equals_literal as an example for other code. This has used strcmp since 2004 in deb84be Closes GH-6555
1 parent a25886d commit 0d99628

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
(un)serializing __PHP_Incomplete_Class instance edge case
3+
--FILE--
4+
<?php
5+
6+
$serialized = 'O:8:"Missing_":1:{s:33:"__PHP_Incomplete_Class_Name' . "\0" . 'other";i:123;}';
7+
ob_start();
8+
$o = unserialize($serialized);
9+
var_dump($o);
10+
$reserialized = serialize($o);
11+
var_dump(unserialize($reserialized));
12+
// Pretty print null bytes
13+
echo str_replace("\0", "\\0", ob_get_clean());
14+
15+
// The serialization should have a property count of 1 and a property set with 1 element.
16+
var_export($reserialized);
17+
echo "\n";
18+
?>
19+
--EXPECT--
20+
object(__PHP_Incomplete_Class)#1 (2) {
21+
["__PHP_Incomplete_Class_Name"]=>
22+
string(8) "Missing_"
23+
["__PHP_Incomplete_Class_Name\0other"]=>
24+
int(123)
25+
}
26+
object(__PHP_Incomplete_Class)#2 (2) {
27+
["__PHP_Incomplete_Class_Name"]=>
28+
string(8) "Missing_"
29+
["__PHP_Incomplete_Class_Name\0other"]=>
30+
int(123)
31+
}
32+
'O:8:"Missing_":1:{s:33:"__PHP_Incomplete_Class_Name' . "\0" . 'other";i:123;}'

ext/standard/var.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable
878878
zend_ulong index;
879879

880880
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, index, key, data) {
881-
if (incomplete_class && strcmp(ZSTR_VAL(key), MAGIC_MEMBER) == 0) {
881+
if (incomplete_class && zend_string_equals_literal(key, MAGIC_MEMBER)) {
882882
continue;
883883
}
884884

0 commit comments

Comments
 (0)