Skip to content

Commit 8b2959b

Browse files
committed
pack and packb raises ValueError when extra data passed.
1 parent 4d64389 commit 8b2959b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

msgpack/_msgpack.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
257257
ctx.user.list_hook = <PyObject*>list_hook
258258
ret = template_execute(&ctx, buf, buf_len, &off)
259259
if ret == 1:
260-
return template_data(&ctx)
260+
obj = template_data(&ctx)
261+
if off < buf_len:
262+
raise ValueError("Extra data.")
263+
return obj
261264
else:
262265
return None
263266

@@ -461,7 +464,7 @@ cdef class Unpacker(object):
461464
if self.file_like is not None:
462465
self.read_from_file()
463466
continue
464-
raise StopIteration("No more unpack data.")
467+
raise StopIteration("No more data to unpack.")
465468
else:
466469
raise ValueError("Unpack failed: error = %d" % (ret,))
467470

0 commit comments

Comments
 (0)