mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-141311: Avoid assertion in BytesIO.readinto() (GH-141333) (GH-141457)
Fix error in assertion which causes failure if pos is equal to PY_SSIZE_T_MAX.
Fix undefined behavior in read() and readinto() if pos is larger that the size
of the underlying buffer.
(cherry picked from commit 7d54374f9c)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
This commit is contained in:
parent
b883ad17cd
commit
75b5157e84
3 changed files with 29 additions and 3 deletions
|
|
@ -54,6 +54,12 @@ def testSeek(self):
|
|||
self.assertEqual(buf[3:], bytesIo.read())
|
||||
self.assertRaises(TypeError, bytesIo.seek, 0.0)
|
||||
|
||||
self.assertEqual(sys.maxsize, bytesIo.seek(sys.maxsize))
|
||||
self.assertEqual(self.EOF, bytesIo.read(4))
|
||||
|
||||
self.assertEqual(sys.maxsize - 2, bytesIo.seek(sys.maxsize - 2))
|
||||
self.assertEqual(self.EOF, bytesIo.read(4))
|
||||
|
||||
def testTell(self):
|
||||
buf = self.buftype("1234567890")
|
||||
bytesIo = self.ioclass(buf)
|
||||
|
|
@ -552,6 +558,14 @@ def test_relative_seek(self):
|
|||
memio.seek(1, 1)
|
||||
self.assertEqual(memio.read(), buf[1:])
|
||||
|
||||
def test_issue141311(self):
|
||||
memio = self.ioclass()
|
||||
# Seek allows PY_SSIZE_T_MAX, read should handle that.
|
||||
# Past end of buffer read should always return 0 (EOF).
|
||||
self.assertEqual(sys.maxsize, memio.seek(sys.maxsize))
|
||||
buf = bytearray(2)
|
||||
self.assertEqual(0, memio.readinto(buf))
|
||||
|
||||
def test_unicode(self):
|
||||
memio = self.ioclass()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue