mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210) (GH-111314)
(cherry picked from commit 9da98c0d9a
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
5e94556f83
commit
45c0b38880
3 changed files with 20 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue