Skip to content

Commit 145abab

Browse files
[3.15] gh-160781: Only test BytesIO write overflow on the C implementation (GH-160903) (#160911)
(cherry picked from commit 8dbc313) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 32b2550 commit 145abab

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎Lib/test/test_io/test_memoryio.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,6 @@ def test_issue141311(self):
565565
self.assertEqual(sys.maxsize, memio.seek(sys.maxsize))
566566
buf = bytearray(2)
567567
self.assertEqual(0, memio.readinto(buf))
568-
# Writing there must not overflow the buffer size.
569-
memio.seek(sys.maxsize - 1)
570-
self.assertRaises((MemoryError, OverflowError), memio.write, b"x")
571-
self.assertEqual(memio.getvalue(), b"")
572568

573569
def test_unicode(self):
574570
memio = self.ioclass()
@@ -891,6 +887,15 @@ def __index__(self):
891887
self.assertEqual(stream.truncate(2**31), 2**31)
892888
self.assertEqual(stream.getvalue(), b'abc')
893889

890+
def test_write_overflow(self):
891+
# gh-160781: overallocation at a position near sys.maxsize
892+
# must raise OverflowError, not SystemError.
893+
memio = self.ioclass()
894+
memio.seek(sys.maxsize - 1)
895+
self.assertRaises(OverflowError, memio.write, b"x")
896+
self.assertEqual(memio.getvalue(), b"")
897+
self.assertEqual(memio.tell(), sys.maxsize - 1)
898+
894899
def test_readinto_overlapping_buffer(self):
895900
with self.ioclass(b'abcd') as stream:
896901
with stream.getbuffer()[1:] as target:

0 commit comments

Comments
 (0)