Skip to content

Commit d90b952

Browse files
[3.14] gh-160781: Only test BytesIO write overflow on the C implementation (GH-160903) (#160910)
(cherry picked from commit 8dbc313) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 719cdc0 commit d90b952

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎Lib/test/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()
@@ -892,6 +888,15 @@ def __index__(self):
892888
self.assertEqual(stream.truncate(2**31), 2**31)
893889
self.assertEqual(stream.getvalue(), b'abc')
894890

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

0 commit comments

Comments
 (0)