Skip to content

Commit cf89f18

Browse files
committed
segfault fixed when data is unpacked using list_hook,
this bug is a twin to msgpack#28. Unit-test is also attached.
1 parent 4ea952f commit cf89f18

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

msgpack/unpack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_obj
163163
{
164164
if (u->list_hook) {
165165
PyObject *new_c = PyEval_CallFunction(u->list_hook, "(O)", *c);
166+
if (!new_c)
167+
return -1;
166168
Py_DECREF(*c);
167169
*c = new_c;
168170
}

msgpack/unpack_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
347347
if(construct_cb(_array_item)(user, c->count, &c->obj, obj) < 0) { goto _failed; }
348348
if(++c->count == c->size) {
349349
obj = c->obj;
350-
construct_cb(_array_end)(user, &obj);
350+
if (construct_cb(_array_end)(user, &obj) < 0) { goto _failed; }
351351
--top;
352352
/*printf("stack pop %d\n", top);*/
353353
goto _push;

test/test_obj.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,13 @@ def test_an_exception_in_objecthook1():
6262
packed = packb({1: {'__complex__': True, 'real': 1, 'imag': 2}})
6363
unpackb(packed, object_hook=bad_complex_decoder)
6464

65+
66+
@raises(DecodeError)
67+
def test_an_exception_in_objecthook2():
68+
packed = packb({1: [{'__complex__': True, 'real': 1, 'imag': 2}]})
69+
unpackb(packed, list_hook=bad_complex_decoder, use_list=1)
70+
71+
72+
6573
if __name__ == '__main__':
6674
main()

0 commit comments

Comments
 (0)