mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Issue #23985: Fix a possible buffer overrun when deleting a slice from the front of a bytearray and then appending some other bytes data.
Patch by Martin Panter.
This commit is contained in:
parent
6371446036
commit
2545411e28
3 changed files with 21 additions and 6 deletions
|
@ -947,6 +947,22 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
|||
b.extend(range(100, 110))
|
||||
self.assertEqual(list(b), list(range(10, 110)))
|
||||
|
||||
def test_fifo_overrun(self):
|
||||
# Test for issue #23985, a buffer overrun when implementing a FIFO
|
||||
# Build Python in pydebug mode for best results.
|
||||
b = bytearray(10)
|
||||
b.pop() # Defeat expanding buffer off-by-one quirk
|
||||
del b[:1] # Advance start pointer without reallocating
|
||||
b += bytes(2) # Append exactly the number of deleted bytes
|
||||
del b # Free memory buffer, allowing pydebug verification
|
||||
|
||||
def test_del_expand(self):
|
||||
# Reducing the size should not expand the buffer (issue #23985)
|
||||
b = bytearray(10)
|
||||
size = sys.getsizeof(b)
|
||||
del b[:1]
|
||||
self.assertLessEqual(sys.getsizeof(b), size)
|
||||
|
||||
def test_extended_set_del_slice(self):
|
||||
indices = (0, None, 1, 3, 19, 300, 1<<333, -1, -2, -31, -300)
|
||||
for start in indices:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue