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

Commit aaf6ed3

Browse files
Demonstrate a bug
1 parent 38357b9 commit aaf6ed3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

test/test_discrepancy.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import io
2+
from pytest import raises, mark
3+
4+
try:
5+
from msgpack import _cmsgpack
6+
except ImportError:
7+
_cmsgpack = None
8+
9+
10+
@mark.skipif(_cmsgpack is None, reason="C extension not awailable")
11+
@mark.parametrize("use_unpack", [True, False])
12+
def test_exceed_max_buffer_size(use_unpack):
13+
"""The C extension used to have a bug: when reading objects that require
14+
a buffer bigger than max_buffer_size it would behave as if there is not
15+
enough data"""
16+
buffer_size = 11
17+
max_buffer_size = 10
18+
f = io.BytesIO(b"\xc6" + buffer_size.to_bytes(4, "big") + b"z" * buffer_size)
19+
u = _cmsgpack.Unpacker(f, max_buffer_size=max_buffer_size)
20+
21+
with raises(ValueError):
22+
if use_unpack:
23+
u.unpack()
24+
else:
25+
next(u)

0 commit comments

Comments
 (0)