diff options
author | DarioDaF <dario.fagotto@gmail.com> | 2022-12-10 23:07:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 23:07:02 (GMT) |
commit | 1bb68ba6d9de6bb7f00aee11d135123163f15887 (patch) | |
tree | 1be51c00ff9587e32cd497b2948506b65f7cbf4b /Lib/asyncio | |
parent | d5f8a2b6ad408368e728a389da918cead3ef7ee9 (diff) | |
download | cpython-1bb68ba6d9de6bb7f00aee11d135123163f15887.zip cpython-1bb68ba6d9de6bb7f00aee11d135123163f15887.tar.gz cpython-1bb68ba6d9de6bb7f00aee11d135123163f15887.tar.bz2 |
gh-99941: Ensure that asyncio.Protocol.data_received receives immutable bytes (#100053)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/proactor_events.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/streams.py | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index c6aab40..1e2a730 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -288,7 +288,8 @@ class _ProactorReadPipeTransport(_ProactorBasePipeTransport, # we got end-of-file so no need to reschedule a new read return - data = self._data[:length] + # It's a new slice so make it immutable so protocols upstream don't have problems + data = bytes(memoryview(self._data)[:length]) else: # the future will be replaced by next proactor.recv call fut.cancel() diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index 3bd9904..0f9098b 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -688,7 +688,7 @@ class StreamReader: await self._wait_for_data('read') # This will work right even if buffer is less than n bytes - data = bytes(self._buffer[:n]) + data = bytes(memoryview(self._buffer)[:n]) del self._buffer[:n] self._maybe_resume_transport() @@ -730,7 +730,7 @@ class StreamReader: data = bytes(self._buffer) self._buffer.clear() else: - data = bytes(self._buffer[:n]) + data = bytes(memoryview(self._buffer)[:n]) del self._buffer[:n] self._maybe_resume_transport() return data |