Kaydet (Commit) e814a39e authored tarafından Michael Merickel's avatar Michael Merickel Kaydeden (comit) Joffrey F

do not assume that read will consume the number of bytes requested

The issue is that ``os.read`` does not always read the expected number of
bytes, and thus we are moving to the next frame too early causing drift
in the byte stream. When the reading drifts, it starts reading garbage
as the next frame size. The some examples of frame sizes were
4032897957 bytes, etc. Values this large were causing the exceptions
from ``os.read``.

fixes #1211
Signed-off-by: 's avatarMichael Merickel <michael@merickel.org>
üst 36df7e4b
......@@ -69,7 +69,11 @@ def frames_iter(socket):
"""
Returns a generator of frames read from socket
"""
n = next_frame_size(socket)
while n > 0:
yield read(socket, n)
while True:
n = next_frame_size(socket)
if n == 0:
break
while n > 0:
result = read(socket, n)
n -= len(result)
yield result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment