From 5c0467a533a9d186d1b9000b60790b363928e85d Mon Sep 17 00:00:00 2001 From: FuNK3Y Date: Sat, 19 Jul 2025 12:14:17 +0000 Subject: [PATCH] python-ecosys/aiohttp: Fix partial reads. Signed-off-by: FuNK3Y --- python-ecosys/aiohttp/aiohttp/__init__.py | 8 +++++++- python-ecosys/aiohttp/aiohttp/aiohttp_ws.py | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/python-ecosys/aiohttp/aiohttp/__init__.py b/python-ecosys/aiohttp/aiohttp/__init__.py index 8c5493f30..2edc4d1dc 100644 --- a/python-ecosys/aiohttp/aiohttp/__init__.py +++ b/python-ecosys/aiohttp/aiohttp/__init__.py @@ -42,7 +42,13 @@ def _decode(self, data): return data async def read(self, sz=-1): - return self._decode(await self.content.read(sz)) + if sz == -1: + return self._decode(await self.content.read(sz)) + data = bytearray() + while sz > 0: + data.extend(await self.content.read(sz)) + sz -= len(data) + return self._decode(data) async def text(self, encoding="utf-8"): return (await self.read(int(self._get_header("content-length", -1)))).decode(encoding) diff --git a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py index 6e0818c92..3b5e92aac 100644 --- a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py +++ b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py @@ -203,7 +203,10 @@ async def _read_frame(self): if has_mask: # pragma: no cover mask = await self.reader.read(4) - payload = await self.reader.read(length) + payload = bytearray() + while length > 0: + payload.extend(await self.reader.read(length)) + length -= len(payload) if has_mask: # pragma: no cover payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload)) return opcode, payload