Skip to content

Commit d57e369

Browse files
committed
Fix unpacker doesn't raise exception for invalid input (Merge branch '0.2'
Fixes #40 Conflicts: ChangeLog.rst msgpack/_unpacker.pyx msgpack/_version.py
2 parents 7b11a42 + 72416e4 commit d57e369

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

msgpack/_unpacker.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cdef extern from "unpack.h":
3838
PyObject* key
3939

4040
ctypedef int (*execute_fn)(template_context* ctx, const_char_ptr data,
41-
size_t len, size_t* off) except -1
41+
size_t len, size_t* off) except? -1
4242
execute_fn template_construct
4343
execute_fn template_skip
4444
execute_fn read_array_header
@@ -113,6 +113,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
113113
if off < buf_len:
114114
raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off))
115115
return obj
116+
elif ret < 0:
117+
raise ValueError("Unpack failed: error = %d" % (ret,))
116118
else:
117119
raise UnpackValueError
118120

test/test_except.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import datetime
88

9+
910
class DummyException(Exception):
1011
pass
1112

@@ -28,6 +29,11 @@ def hook(obj):
2829
object_pairs_hook=hook)
2930

3031

32+
@raises(ValueError)
33+
def test_invalidvalue():
34+
unpackb(b'\xd9\x97#DL_')
35+
36+
3137
if __name__ == '__main__':
3238
from nose import main
3339
main()

0 commit comments

Comments
 (0)