Skip to content

Commit f245ef4

Browse files
author
Mirko Vogt
committed
aiohttp: fix partial read on websocket resulting in truncated payload
Attempting to read N bytes from a socket does not guarantee to actually read N bytes, even if >= N bytes were written onto the peer socket. This especially becomes an issues when attempting to read larger messages at once, which then potentially can't be read all at once, resulting in truncated payloads. Fix that by reading as long / often until expected length was actually received.
1 parent 50ed36f commit f245ef4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

python-ecosys/aiohttp/aiohttp/aiohttp_ws.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ async def _read_frame(self):
203203

204204
if has_mask: # pragma: no cover
205205
mask = await self.reader.read(4)
206-
payload = await self.reader.read(length)
206+
payload = b""
207+
while len(payload) < length:
208+
payload += await self.reader.read(length)
207209
if has_mask: # pragma: no cover
208210
payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
209211
return opcode, payload

0 commit comments

Comments
 (0)