diff options
author | INADA Naoki <inada-n@klab.com> | 2012-12-29 01:39:59 +0900 |
---|---|---|
committer | INADA Naoki <inada-n@klab.com> | 2012-12-29 01:39:59 +0900 |
commit | 72416e403c6d70b6fbc4ea8e05e1fe7f02a6561a (patch) | |
tree | 9874a48273c5869993cd31dbab4ac7f426a77633 | |
parent | 9dc299bd8da75e61f512e6ba50bd06face71f8a0 (diff) | |
download | msgpack-python-0.2.tar.gz |
Fix unpacker doesn't raise exception for invalid input.0.2
-rw-r--r-- | msgpack/_msgpack.pyx | 4 | ||||
-rw-r--r-- | test/test_except.py | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/msgpack/_msgpack.pyx b/msgpack/_msgpack.pyx index 5feba11..78b2aa7 100644 --- a/msgpack/_msgpack.pyx +++ b/msgpack/_msgpack.pyx @@ -210,7 +210,7 @@ cdef extern from "unpack.h": PyObject* key int template_execute(template_context* ctx, const_char_ptr data, - size_t len, size_t* off, bint construct) except -1 + size_t len, size_t* off, bint construct) except? -1 void template_init(template_context* ctx) object template_data(template_context* ctx) @@ -285,6 +285,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None, if off < buf_len: raise ValueError("Extra data.") return obj + elif ret < 0: + raise ValueError("Unpack failed: error = %d" % (ret,)) else: return None diff --git a/test/test_except.py b/test/test_except.py index e142dd6..35287df 100644 --- a/test/test_except.py +++ b/test/test_except.py @@ -6,6 +6,7 @@ from msgpack import packb, unpackb import datetime + class DummyException(Exception): pass @@ -28,6 +29,11 @@ def test_raise_from_object_hook(): object_pairs_hook=hook) +@raises(ValueError) +def test_invalidvalue(): + unpackb(b'\xd9\x97#DL_') + + if __name__ == '__main__': from nose import main main() |