Skip to content

Commit a0a7cba

Browse files
committed
fix #149
1 parent ec63358 commit a0a7cba

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

msgpack_unpack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static inline void msgpack_var_replace(zval *old, zval *new) /* {{{ */ {
116116
static zval *msgpack_var_access(msgpack_unserialize_data_t *var_hashx, zend_long id) /* {{{ */ {
117117
var_entries *var_hash = var_hashx->first;
118118

119-
while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
119+
while (id > VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
120120
var_hash = var_hash->next;
121121
id -= VAR_ENTRIES_MAX;
122122
}
@@ -125,7 +125,7 @@ static zval *msgpack_var_access(msgpack_unserialize_data_t *var_hashx, zend_long
125125
return NULL;
126126
}
127127

128-
if (id > 0 && id < var_hash->used_slots) {
128+
if (id > 0 && id <= var_hash->used_slots) {
129129
zval *zv = &var_hash->data[id - 1];
130130
if (UNEXPECTED(Z_TYPE_P(zv) == IS_INDIRECT)) {
131131
zv = Z_INDIRECT_P(zv);

tests/issue149.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Issue #149 (msgpack (un)pack error with serialize())
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("msgpack")) {
6+
echo "skip";
7+
}
8+
--INI--
9+
msgpack.php_only=1
10+
--FILE--
11+
Test
12+
<?php
13+
$data = unserialize(file_get_contents(__DIR__."/issue149.ser.txt"));
14+
$check = msgpack_unpack(msgpack_pack($data));
15+
var_dump($check == $data);
16+
?>
17+
OK
18+
--EXPECT--
19+
Test
20+
bool(true)
21+
OK

tests/issue149.ser.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)