Skip to content
Closed
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
32 changes: 32 additions & 0 deletions ext/standard/tests/serialize/incomplete_class_magic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
(un)serializing __PHP_Incomplete_Class instance edge case
--FILE--
<?php

$serialized = 'O:8:"Missing_":1:{s:33:"__PHP_Incomplete_Class_Name' . "\0" . 'other";i:123;}';
ob_start();
$o = unserialize($serialized);
var_dump($o);
$reserialized = serialize($o);
var_dump(unserialize($reserialized));
// Pretty print null bytes
echo str_replace("\0", "\\0", ob_get_clean());

// The serialization should have a property count of 1 and a property set with 1 element.
var_export($reserialized);
echo "\n";
?>
--EXPECT--
object(__PHP_Incomplete_Class)#1 (2) {
["__PHP_Incomplete_Class_Name"]=>
string(8) "Missing_"
["__PHP_Incomplete_Class_Name\0other"]=>
int(123)
}
object(__PHP_Incomplete_Class)#2 (2) {
["__PHP_Incomplete_Class_Name"]=>
string(8) "Missing_"
["__PHP_Incomplete_Class_Name\0other"]=>
int(123)
}
'O:8:"Missing_":1:{s:33:"__PHP_Incomplete_Class_Name' . "\0" . 'other";i:123;}'
2 changes: 1 addition & 1 deletion ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable
zend_ulong index;

ZEND_HASH_FOREACH_KEY_VAL_IND(ht, index, key, data) {
if (incomplete_class && strcmp(ZSTR_VAL(key), MAGIC_MEMBER) == 0) {
if (incomplete_class && zend_string_equals_literal(key, MAGIC_MEMBER)) {
continue;
}

Expand Down