diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-10-25 11:25:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 11:25:31 (GMT) |
commit | 45c0b388809d561750c4f0c791de6ec571215d26 (patch) | |
tree | ce0923f2508ccf1c3fa251b8fa3377b5b29d7603 /Lib | |
parent | 5e94556f83256440c88f5342cb7908a96f178c0e (diff) | |
download | cpython-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.py | 14 |
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) |