summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2013-02-23 18:11:46 +0900
committerINADA Naoki <inada-n@klab.com>2013-02-23 18:11:46 +0900
commit38a9ad98c9e8e8b73efb9726554737a60ec215c9 (patch)
treeda34edb37f4446de89bfe85de2e9b4ee1ca53f9b
parenta6859791a2048f5b2aae1ece03a603af63d69633 (diff)
downloadmsgpack-python-38a9ad98c9e8e8b73efb9726554737a60ec215c9.tar.gz
Revert skipping reserved byte.
-rw-r--r--msgpack/fallback.py9
-rw-r--r--msgpack/unpack_template.h87
2 files changed, 45 insertions, 51 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index f893e1a..e9dddd6 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -48,7 +48,7 @@ from msgpack.exceptions import (
PackValueError,
ExtraData)
-EX_SKIP = 0
+EX_SKIP = 0
EX_CONSTRUCT = 1
EX_READ_ARRAY_HEADER = 2
EX_READ_MAP_HEADER = 3
@@ -57,7 +57,6 @@ TYPE_IMMEDIATE = 0
TYPE_ARRAY = 1
TYPE_MAP = 2
TYPE_RAW = 3
-TYPE_RESERVED = 4
DEFAULT_RECURSE_LIMIT=511
@@ -338,13 +337,11 @@ class Unpacker(object):
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
typ = TYPE_MAP
else:
- typ = TYPE_RESERVED
+ raise UnpackValueError("Unknown header: 0x%x" % b)
return typ, n, obj
def _fb_unpack(self, execute=EX_CONSTRUCT, write_bytes=None):
- typ = TYPE_RESERVED
- while typ == TYPE_RESERVED:
- typ, n, obj = self._read_header(execute, write_bytes)
+ typ, n, obj = self._read_header(execute, write_bytes)
if execute == EX_READ_ARRAY_HEADER:
if typ != TYPE_ARRAY:
diff --git a/msgpack/unpack_template.h b/msgpack/unpack_template.h
index 8fd179d..83b6918 100644
--- a/msgpack/unpack_template.h
+++ b/msgpack/unpack_template.h
@@ -422,56 +422,53 @@ _end:
template <unsigned int fixed_offset, unsigned int var_offset>
msgpack_unpack_func(int, _container_header)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
{
- for (;;) {
- if (len < *off) {
- return 0;
- }
- uint32_t size;
- const unsigned char *const p = (unsigned char*)data + *off;
+ assert(len >= *off);
+ uint32_t size;
+ const unsigned char *const p = (unsigned char*)data + *off;
#define inc_offset(inc) \
- if (len - *off < inc) \
- return 0; \
- *off += inc;
-
- switch (*p) {
- case var_offset:
- inc_offset(3);
- size = _msgpack_load16(uint16_t, p + 1);
- break;
- case var_offset + 1:
- inc_offset(5);
- size = _msgpack_load32(uint32_t, p + 1);
- break;
+ if (len - *off < inc) \
+ return 0; \
+ *off += inc;
+
+ switch (*p) {
+ case var_offset:
+ inc_offset(3);
+ size = _msgpack_load16(uint16_t, p + 1);
+ break;
+ case var_offset + 1:
+ inc_offset(5);
+ size = _msgpack_load32(uint32_t, p + 1);
+ break;
#ifdef USE_CASE_RANGE
- case fixed_offset + 0x0 ... fixed_offset + 0xf:
+ case fixed_offset + 0x0 ... fixed_offset + 0xf:
#else
- case fixed_offset + 0x0:
- case fixed_offset + 0x1:
- case fixed_offset + 0x2:
- case fixed_offset + 0x3:
- case fixed_offset + 0x4:
- case fixed_offset + 0x5:
- case fixed_offset + 0x6:
- case fixed_offset + 0x7:
- case fixed_offset + 0x8:
- case fixed_offset + 0x9:
- case fixed_offset + 0xa:
- case fixed_offset + 0xb:
- case fixed_offset + 0xc:
- case fixed_offset + 0xd:
- case fixed_offset + 0xe:
- case fixed_offset + 0xf:
+ case fixed_offset + 0x0:
+ case fixed_offset + 0x1:
+ case fixed_offset + 0x2:
+ case fixed_offset + 0x3:
+ case fixed_offset + 0x4:
+ case fixed_offset + 0x5:
+ case fixed_offset + 0x6:
+ case fixed_offset + 0x7:
+ case fixed_offset + 0x8:
+ case fixed_offset + 0x9:
+ case fixed_offset + 0xa:
+ case fixed_offset + 0xb:
+ case fixed_offset + 0xc:
+ case fixed_offset + 0xd:
+ case fixed_offset + 0xe:
+ case fixed_offset + 0xf:
#endif
- ++*off;
- size = ((unsigned int)*p) & 0x0f;
- break;
- default:
- continue;
- }
- msgpack_unpack_callback(_uint32)(&ctx->user, size, &ctx->stack[0].obj);
- return 1;
- }
+ ++*off;
+ size = ((unsigned int)*p) & 0x0f;
+ break;
+ default:
+ PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream");
+ return -1;
+ }
+ msgpack_unpack_callback(_uint32)(&ctx->user, size, &ctx->stack[0].obj);
+ return 1;
}
#undef SWITCH_RANGE_BEGIN