summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_memoryio.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-10-25 10:50:16 (GMT)
committerGitHub <noreply@github.com>2023-10-25 10:50:16 (GMT)
commit9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b (patch)
tree6d4daecc496a574b2920ffda4e3703dd413c4315 /Lib/test/test_memoryio.py
parentf6a45a03d0e0ef6b00c45a0de9a606b1d23cbd2f (diff)
downloadcpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.zip
cpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.tar.gz
cpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.tar.bz2
gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210)
Diffstat (limited to 'Lib/test/test_memoryio.py')
-rw-r--r--Lib/test/test_memoryio.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index cd2faba..7312992 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -463,6 +463,20 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
memio.close()
self.assertRaises(ValueError, memio.getbuffer)
+ def test_getbuffer_empty(self):
+ memio = self.ioclass()
+ buf = memio.getbuffer()
+ self.assertEqual(bytes(buf), b"")
+ # Trying to change the size of the BytesIO while a buffer is exported
+ # raises a BufferError.
+ self.assertRaises(BufferError, memio.write, b'x')
+ buf2 = memio.getbuffer()
+ self.assertRaises(BufferError, memio.write, b'x')
+ buf.release()
+ self.assertRaises(BufferError, memio.write, b'x')
+ buf2.release()
+ memio.write(b'x')
+
def test_read1(self):
buf = self.buftype("1234567890")
self.assertEqual(self.ioclass(buf).read1(), buf)