summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2012-09-23 03:39:14 +0900
committerINADA Naoki <inada-n@klab.com>2012-09-23 03:39:14 +0900
commit8b2959bc0ab086a3dbe47176b3c241dd1a1ecf6c (patch)
treeaa9e8f4523f215aab4c70e004074711f69c20545
parent4d643894a1ab02b0836245b8a456200cac5ae314 (diff)
downloadmsgpack-python-8b2959bc0ab086a3dbe47176b3c241dd1a1ecf6c.tar.gz
pack and packb raises ValueError when extra data passed.
-rw-r--r--msgpack/_msgpack.pyx7
1 files changed, 5 insertions, 2 deletions
diff --git a/msgpack/_msgpack.pyx b/msgpack/_msgpack.pyx
index 976871e..12ee2ea 100644
--- a/msgpack/_msgpack.pyx
+++ b/msgpack/_msgpack.pyx
@@ -257,7 +257,10 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
ctx.user.list_hook = <PyObject*>list_hook
ret = template_execute(&ctx, buf, buf_len, &off)
if ret == 1:
- return template_data(&ctx)
+ obj = template_data(&ctx)
+ if off < buf_len:
+ raise ValueError("Extra data.")
+ return obj
else:
return None
@@ -461,7 +464,7 @@ cdef class Unpacker(object):
if self.file_like is not None:
self.read_from_file()
continue
- raise StopIteration("No more unpack data.")
+ raise StopIteration("No more data to unpack.")
else:
raise ValueError("Unpack failed: error = %d" % (ret,))