mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140607: Validate returned byte count in RawIOBase.read (#140611)
While `RawIOBase.readinto` should return a count of bytes between 0 and the length of the given buffer, it is not required to. Add validation inside RawIOBase.read() that the returned byte count is valid. Co-authored-by: Shamil <ashm.tech@proton.me> Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
313145eab5
commit
0f0a362768
4 changed files with 30 additions and 3 deletions
|
|
@ -617,6 +617,8 @@ def read(self, size=-1):
|
|||
n = self.readinto(b)
|
||||
if n is None:
|
||||
return None
|
||||
if n < 0 or n > len(b):
|
||||
raise ValueError(f"readinto returned {n} outside buffer size {len(b)}")
|
||||
del b[n:]
|
||||
return bytes(b)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue