diff options
-rw-r--r-- | msgpack/fallback.py | 5 | ||||
-rw-r--r-- | test/test_sequnpack.py | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py index d1f39d1..bd99a15 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -195,6 +195,9 @@ class Unpacker(object): # the buffer is not "consumed" completely, for efficiency sake. # Instead, it is done sloppily. To make sure we raise BufferFull at # the correct moments, we have to keep track of how sloppy we were. + # Furthermore, when the buffer is incomplete (that is: in the case + # we raise an OutOfData) we need to rollback the buffer to the correct + # state, which _fb_slopiness records. self._fb_sloppiness = 0 self._max_buffer_size = max_buffer_size or 2**31-1 if read_size > self._max_buffer_size: @@ -283,7 +286,7 @@ class Unpacker(object): def _fb_rollback(self): self._fb_buf_i = 0 - self._fb_buf_o = 0 + self._fb_buf_o = self._fb_sloppiness def _fb_get_extradata(self): bufs = self._fb_buffers[self._fb_buf_i:] diff --git a/test/test_sequnpack.py b/test/test_sequnpack.py index 5d37698..45f4cc7 100644 --- a/test/test_sequnpack.py +++ b/test/test_sequnpack.py @@ -84,3 +84,15 @@ def test_readbytes(): assert unpacker.read_bytes(3) == b'oob' assert unpacker.unpack() == ord(b'a') assert unpacker.unpack() == ord(b'r') + +def test_issue124(): + unpacker = Unpacker() + unpacker.feed(b'\xa1?\xa1!') + assert tuple(unpacker) == (b'?', b'!') + assert tuple(unpacker) == () + unpacker.feed(b"\xa1?\xa1") + assert tuple(unpacker) == (b'?',) + assert tuple(unpacker) == () + unpacker.feed(b"!") + assert tuple(unpacker) == (b'!',) + assert tuple(unpacker) == () |