10000 Merge pull request #125 from bwesterb/master · overcastcloud/msgpack-python@3f5e058 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f5e058

Browse files
committed
Merge pull request msgpack#125 from bwesterb/master
Rollback to correct position in the case of OutOfData. Fixes msgpack#124
2 parents 68b0294 + c5d6218 commit 3f5e058

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

msgpack/fallback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
195195
# the buffer is not "consumed" completely, for efficiency sake.
196196
# Instead, it is done sloppily. To make sure we raise BufferFull at
197197
# the correct moments, we have to keep track of how sloppy we were.
198+
# Furthermore, when the buffer is incomplete (that is: in the case
199+
# we raise an OutOfData) we need to rollback the buffer to the correct
200+
# state, which _fb_slopiness records.
198201
self._fb_sloppiness = 0
199202
self._max_buffer_size = max_buffer_size or 2**31-1
200203
if read_size > self._max_buffer_size:
@@ -283,7 +286,7 @@ def read_bytes(self, n):
283286

284287
def _fb_rollback(self):
285288
self._fb_buf_i = 0
286-
self._fb_buf_o = 0
289+
self._fb_buf_o = self._fb_sloppiness
287290

288291
def _fb_get_extradata(self):
289292
bufs = self._fb_buffers[self._fb_buf_i:]

test/test_sequnpack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ def test_readbytes():
8484
assert unpacker.read_bytes(3) == b'oob'
8585
assert unpacker.unpack() == ord(b'a')
8686
assert unpacker.unpack() == ord(b'r')
87+
88+
def test_issue124():
89+
unpacker = Unpacker()
90+
unpacker.feed(b'\xa1?\xa1!')
91+
assert tuple(unpacker) == (b'?', b'!')
92+
assert tuple(unpacker) == ()
93+
unpacker.feed(b"\xa1?\xa1")
94+
assert tuple(unpacker) == (b'?',)
95+
assert tuple(unpacker) == ()
96+
unpacker.feed(b"!")
97+
assert tuple(unpacker) == (b'!',)
98+
assert tuple(unpacker) == ()

0 commit comments

Comments
 (0)
0