Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 8feb8dc

Browse files
Remove test_max_str_len
It appears this test was verifying a quirk of the DoS protection. When the input is supplied via feed() BufferFull is raised to prevent excessive memory allocation. When the input is supplied via a file ValueError is raised when the length of the bin, str or ext is too big. The fallback implementation had a quirk: it would raise ValueError when the length of the is too big even when the input is supplied via feed(). As far as I can tell removing this quirk does not introduce a vulnerability. I have fixed the quirk making this test obsolete. This also allowed me to remove the code from the extension the appears to serve only one purpose: make this test pass.
1 parent 535fd96 commit 8feb8dc

2 files changed

Lines changed: 0 additions & 19 deletions

File tree

msgpack/unpack.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object*
231231

232232
static inline int unpack_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
233233
{
234-
if (l > u->max_str_len) {
235-
PyErr_Format(PyExc_ValueError, "%u exceeds max_str_len(%zd)", l, u->max_str_len);
236-
return -1;
237-
}
238-
239234
PyObject *py;
240235

241236
if (u->raw) {

test/test_limits.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ def test_map_header():
4141
packer.pack_array_header(2 ** 32)
4242

4343

44-
def test_max_str_len():
45-
d = "x" * 3
46-
packed = packb(d)
47-
48-
unpacker = Unpacker(max_str_len=3, raw=False)
49-
unpacker.feed(packed)
50-
assert unpacker.unpack() == d
51-
52-
unpacker = Unpacker(max_str_len=2, raw=False)
53-
with pytest.raises(UnpackValueError):
54-
unpacker.feed(packed)
55-
unpacker.unpack()
56-
57-
5844
def test_max_array_len():
5945
d = [1, 2, 3]
6046
packed = packb(d)

0 commit comments

Comments
 (0)