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
8 changes: 8 additions & 0 deletions msgpack_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
}

if (ht) {
#if PHP_VERSION_ID < 70000
n = zend_hash_num_elements(ht);
#else
n = zend_array_count(ht);
#endif
} else {
n = 0;
}
Expand Down Expand Up @@ -264,7 +268,11 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
zend_ulong key_long;
zval *value, *value_noref;

#if PHP_VERSION_ID < 70000
ZEND_HASH_FOREACH_KEY_VAL(ht, key_long, key_str, value) {
#else
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key_long, key_str, value) {
#endif
if (key_str && incomplete_class && strcmp(ZSTR_VAL(key_str), MAGIC_MEMBER) == 0) {
continue;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/bug002.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Bug #2 (Deserializing a large array of nested objects gives "zend_mm_heap corrupted")
Bug #2 (Deserializing a large array of nested objects used to give "zend_mm_heap corrupted", now gives parse error)
--XFAIL--
Bug is not fixed yet
--SKIPIF--
Expand All @@ -21,8 +21,14 @@ for ($i = 0; $i < 1024; $i++) {
$tmp = &$tmp[0];
}

// Count the number of first-array-elements to confirm the large data structure
var_dump(substr_count(print_r($data, true), "[0]"));

$newdata = msgpack_unserialize(msgpack_serialize($data));
var_dump($newdata == $data);
?>
--EXPECTF--
bool(true)
int(1024)

Warning: [msgpack] (php_msgpack_unserialize) Parse error in %s on line %d
bool(false)
Binary file added tests/issue081.phpt
Binary file not shown.