Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions msgpack/unpack_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,15 @@ static inline int unpack_execute(bool construct, unpack_context* ctx, const char
again_fixed_trail_if_zero(ACS_EXT_VALUE,
_msgpack_load16(uint16_t,n)+1,
_ext_zero);
case CS_EXT_32:
again_fixed_trail_if_zero(ACS_EXT_VALUE,
_msgpack_load32(uint32_t,n)+1,
_ext_zero);
case CS_EXT_32: {
uint32_t size = _msgpack_load32(uint32_t,n);
// trail includes the typecode, so size+1 must not wrap around.
if (size == UINT32_MAX) {
PyErr_Format(PyExc_ValueError, "%u exceeds max ext length", size);
goto _failed;
}
again_fixed_trail_if_zero(ACS_EXT_VALUE, size+1, _ext_zero);
}
case CS_FLOAT: {
double f;
#if PY_VERSION_HEX >= 0x030B00A7
Expand Down
9 changes: 9 additions & 0 deletions test/test_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ def test_max_ext_len():
unpacker.unpack()


@pytest.mark.parametrize("method", ["unpack", "skip"])
def test_ext32_max_length(method):
# ext32 with length 0xffffffff followed by bytes that look like another object.
unpacker = Unpacker()
unpacker.feed(b"\xc9\xff\xff\xff\xff" + packb({"a": 1}))
with pytest.raises(UnpackValueError):
getattr(unpacker, method)()


# PyPy fails following tests because of constant folding?
# https://bugs.pypy.org/issue1721
# @pytest.mark.skipif(True, reason="Requires very large memory.")
Expand Down
Loading