https://github.com/python/cpython/commit/d90b95205088837f76278ce2ca9c8bed88adb675
commit: d90b95205088837f76278ce2ca9c8bed88adb675
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-10-29T17:27:55Z
summary:

[3.14] gh-160781: Only test BytesIO write overflow on the C implementation 
(GH-160903) (#160910)

(cherry picked from commit 8dbc313ff9e36d38062532646c6c7faeab560115)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
M Lib/test/test_memoryio.py

diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 967e2390a8a7ee..d134df18d9e847 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -565,10 +565,6 @@ def test_issue141311(self):
         self.assertEqual(sys.maxsize, memio.seek(sys.maxsize))
         buf = bytearray(2)
         self.assertEqual(0, memio.readinto(buf))
-        # Writing there must not overflow the buffer size.
-        memio.seek(sys.maxsize - 1)
-        self.assertRaises((MemoryError, OverflowError), memio.write, b"x")
-        self.assertEqual(memio.getvalue(), b"")
 
     def test_unicode(self):
         memio = self.ioclass()
@@ -892,6 +888,15 @@ def __index__(self):
             self.assertEqual(stream.truncate(2**31), 2**31)
             self.assertEqual(stream.getvalue(), b'abc')
 
+    def test_write_overflow(self):
+        # gh-160781: overallocation at a position near sys.maxsize
+        # must raise OverflowError, not SystemError.
+        memio = self.ioclass()
+        memio.seek(sys.maxsize - 1)
+        self.assertRaises(OverflowError, memio.write, b"x")
+        self.assertEqual(memio.getvalue(), b"")
+        self.assertEqual(memio.tell(), sys.maxsize - 1)
+
     def test_readinto_overlapping_buffer(self):
         with self.ioclass(b'abcd') as stream:
             with stream.getbuffer()[1:] as target:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to