summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-25 11:25:31 (GMT)
committerGitHub <noreply@github.com>2023-10-25 11:25:31 (GMT)
commit45c0b388809d561750c4f0c791de6ec571215d26 (patch)
treece0923f2508ccf1c3fa251b8fa3377b5b29d7603 /Lib
parent5e94556f83256440c88f5342cb7908a96f178c0e (diff)
downloadcpython-45c0b388809d561750c4f0c791de6ec571215d26.zip
cpython-45c0b388809d561750c4f0c791de6ec571215d26.tar.gz
cpython-45c0b388809d561750c4f0c791de6ec571215d26.tar.bz2
[3.12] gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210) (GH-111314)
(cherry picked from commit 9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-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)