Skip to content

Commit e814a39

Browse files
mmerickelshin-
authored andcommitted
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: Michael Merickel <[email protected]>
1 parent 36df7e4 commit e814a39

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docker/utils/socket.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def frames_iter(socket):
6969
"""
7070
Returns a generator of frames read from socket
7171
"""
72-
n = next_frame_size(socket)
73-
while n > 0:
74-
yield read(socket, n)
72+
while True:
7573
n = next_frame_size(socket)
74+
if n == 0:
75+
break
76+
while n > 0:
77+
result = read(socket, n)
78+
n -= len(result)
79+
yield result

0 commit comments

Comments
 (0)