Skip to content

Commit c244a8a

Browse files
committed
fix #139
disallow cloning of MsgpackUnpacker instances to avoid crash when attempted to do so
1 parent 69ff291 commit c244a8a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

msgpack_class.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ void msgpack_init_class() /* {{{ */ {
512512
memcpy(&msgpack_unpacker_handlers, zend_get_std_object_handlers(),sizeof msgpack_unpacker_handlers);
513513
msgpack_unpacker_handlers.offset = XtOffsetOf(php_msgpack_unpacker_t, object);
514514
msgpack_unpacker_handlers.free_obj = php_msgpack_unpacker_free;
515+
msgpack_unpacker_handlers.clone_obj = NULL;
515516

516517
}
517518
/* }}} */

tests/issue139.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Issue #139 (Segmentation fault when using cloned unpacker)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("msgpack")) {
6+
echo "skip";
7+
}
8+
--FILE--
9+
<?php
10+
try {
11+
$unpacker = new \MessagePackUnpacker(true);
12+
$unpacker = clone $unpacker; // <-- this line is causing the segmentation fault error
13+
$unpacker->feed("\xc3");
14+
$unpacker->execute();
15+
$data = $unpacker->data();
16+
} catch (\Throwable $e) {
17+
echo $e->getMessage(),"\n";
18+
}
19+
?>
20+
OK
21+
--EXPECT--
22+
Trying to clone an uncloneable object of class MessagePackUnpacker
23+
OK

0 commit comments

Comments
 (0)