From 77e1657a52ccbec39f0e7815dc29aeaedebe5fa3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 2 Nov 2024 21:27:27 -0500 Subject: [PATCH 1/4] Avoid slice in the WebSocket reader when the tail is empty --- aiohttp/_websocket/reader_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/_websocket/reader_py.py b/aiohttp/_websocket/reader_py.py index 11f0e53c3c7..8864f234be1 100644 --- a/aiohttp/_websocket/reader_py.py +++ b/aiohttp/_websocket/reader_py.py @@ -363,6 +363,6 @@ def parse_frame( self._frame_payload = bytearray() self._state = READ_HEADER - self._tail = buf[start_pos:] + self._tail = buf[start_pos:] if start_pos < buf_length else b"" return frames From f0c0eb22fd2710d6c6ff9716348785f74902dd6a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 2 Nov 2024 21:44:18 -0500 Subject: [PATCH 2/4] avoid another slice --- aiohttp/_websocket/reader_c.pxd | 1 - aiohttp/_websocket/reader_py.py | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/aiohttp/_websocket/reader_c.pxd b/aiohttp/_websocket/reader_c.pxd index 75291858e84..031c33acb7e 100644 --- a/aiohttp/_websocket/reader_c.pxd +++ b/aiohttp/_websocket/reader_c.pxd @@ -79,7 +79,6 @@ cdef class WebSocketReader: chunk_size="unsigned int", chunk_len="unsigned int", buf_length="unsigned int", - data=bytes, payload=bytearray, first_byte="unsigned char", second_byte="unsigned char", diff --git a/aiohttp/_websocket/reader_py.py b/aiohttp/_websocket/reader_py.py index 8864f234be1..78b51a66e0e 100644 --- a/aiohttp/_websocket/reader_py.py +++ b/aiohttp/_websocket/reader_py.py @@ -246,10 +246,9 @@ def parse_frame( if self._state == READ_HEADER: if buf_length - start_pos < 2: break - data = buf[start_pos : start_pos + 2] start_pos += 2 - first_byte = data[0] - second_byte = data[1] + first_byte = buf[start_pos] + second_byte = buf[start_pos + 1] fin = (first_byte >> 7) & 1 rsv1 = (first_byte >> 6) & 1 From 825f2be463de4425bb80293a1d1a5f5d1ac9e5f6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 2 Nov 2024 21:46:19 -0500 Subject: [PATCH 3/4] avoid another slice --- aiohttp/_websocket/reader_py.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/_websocket/reader_py.py b/aiohttp/_websocket/reader_py.py index 78b51a66e0e..daa5a50d92b 100644 --- a/aiohttp/_websocket/reader_py.py +++ b/aiohttp/_websocket/reader_py.py @@ -246,9 +246,9 @@ def parse_frame( if self._state == READ_HEADER: if buf_length - start_pos < 2: break - start_pos += 2 first_byte = buf[start_pos] second_byte = buf[start_pos + 1] + start_pos += 2 fin = (first_byte >> 7) & 1 rsv1 = (first_byte >> 6) & 1 From c828cca90c3dd5d6a05569af7bf60a73e7ac57f4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 2 Nov 2024 21:52:08 -0500 Subject: [PATCH 4/4] changelog --- CHANGES/9636.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 120000 CHANGES/9636.feature.rst diff --git a/CHANGES/9636.feature.rst b/CHANGES/9636.feature.rst new file mode 120000 index 00000000000..a93584bccd8 --- /dev/null +++ b/CHANGES/9636.feature.rst @@ -0,0 +1 @@ +9543.feature.rst \ No newline at end of file