Permalink
Browse files

segfault fixed when data is unpacked using `list_hook`,

this bug is a twin to #28.
Unit-test is also attached.
  • Loading branch information...
1 parent 4ea952f commit cf89f18be7614d6d55bb9eb7e9bf0e10d42a8508 @drednout drednout committed Oct 12, 2012
Showing with 11 additions and 1 deletion.
  1. +2 −0 msgpack/unpack.h
  2. +1 −1 msgpack/unpack_template.h
  3. +8 −0 test/test_obj.py
View
@@ -163,6 +163,8 @@ static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_obj
{
if (u->list_hook) {
PyObject *new_c = PyEval_CallFunction(u->list_hook, "(O)", *c);
+ if (!new_c)
+ return -1;
Py_DECREF(*c);
*c = new_c;
}
@@ -347,7 +347,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
if(construct_cb(_array_item)(user, c->count, &c->obj, obj) < 0) { goto _failed; }
if(++c->count == c->size) {
obj = c->obj;
- construct_cb(_array_end)(user, &obj);
+ if (construct_cb(_array_end)(user, &obj) < 0) { goto _failed; }
--top;
/*printf("stack pop %d\n", top);*/
goto _push;
View
@@ -62,5 +62,13 @@ def test_an_exception_in_objecthook1():
packed = packb({1: {'__complex__': True, 'real': 1, 'imag': 2}})
unpackb(packed, object_hook=bad_complex_decoder)
+
+@raises(DecodeError)
+def test_an_exception_in_objecthook2():
+ packed = packb({1: [{'__complex__': True, 'real': 1, 'imag': 2}]})
+ unpackb(packed, list_hook=bad_complex_decoder, use_list=1)
+
+
+
if __name__ == '__main__':
main()

0 comments on commit cf89f18

Please sign in to comment.