summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-05-19 20:55:42 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2015-05-19 20:55:42 +0200
commit994fc4e5bfa67a7443eea45bbefc213f7e7ae561 (patch)
tree24e36cebe34fad9bf0a42bd0a1f9fb9012c01a69 /Lib/test/test_bytes.py
parent52a7d9443aa88d8be8080e3f57d57e13e109e21d (diff)
parentd2aa2fdc6f81efaa4b7e3aee7544881260705e77 (diff)
downloadcpython-994fc4e5bfa67a7443eea45bbefc213f7e7ae561.tar.gz
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.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index a075cdeb0e..7ff7f19ef4 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -993,6 +993,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: