8000 Fix unpacker doesn't raise exception for invalid input. · peter80/msgpack-python@72416e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 72416e4

Browse files
committed
Fix unpacker doesn't raise exception for invalid input.
1 parent 9dc299b commit 72416e4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

msgpack/_msgpack.pyx

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

212212
int template_execute(template_context* ctx, const_char_ptr data,
213-
size_t len, size_t* off, bint construct) except -1
213+
size_t len, size_t* off, bint construct) except? -1
214214
void template_init(template_context* ctx)
215215
object template_data(template_context* ctx)
216216

@@ -285,6 +285,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
285285
if off < buf_len:
286286
raise ValueError("Extra data.")
287287
return obj
288+
elif ret < 0:
289+
raise ValueError("Unpack failed: error = %d" % (ret,))
288290
else:
289291
return None
290292

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)
0