summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/bytearray_slice_assign.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-08-15 23:02:04 +1000
committerDamien George <damien.p.george@gmail.com>2019-08-15 23:02:04 +1000
commitacfbb9febd024475bdcb4ebbe2ec8c0e9a652275 (patch)
tree7ed201887084134ccb40db11f9968b3755f5661e /tests/basics/bytearray_slice_assign.py
parentbaeebc557c3132fa17f3c902e260d5049f7c7957 (diff)
downloadmicropython-acfbb9febd024475bdcb4ebbe2ec8c0e9a652275.tar.gz
micropython-acfbb9febd024475bdcb4ebbe2ec8c0e9a652275.zip
py/objarray: Fix amount of free space in array when doing slice assign.
Prior to this patch the amount of free space in an array (including bytearray) was not being maintained correctly for the case of slice assignment which changed the size of the array. Under certain cases (as encoded in the new test) it was possible that the array could grow beyond its allocated memory block and corrupt the heap. Fixes issue #4127.
Diffstat (limited to 'tests/basics/bytearray_slice_assign.py')
-rw-r--r--tests/basics/bytearray_slice_assign.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py
index 7f7d1d119a..fa7878e10d 100644
--- a/tests/basics/bytearray_slice_assign.py
+++ b/tests/basics/bytearray_slice_assign.py
@@ -59,3 +59,10 @@ print(b)
b = bytearray(2)
b[1:1] = b"12345"
print(b)
+
+# Growth of bytearray via slice extension
+b = bytearray(b'12345678')
+b.append(57) # expand and add a bit of unused space at end of the bytearray
+for i in range(400):
+ b[-1:] = b'ab' # grow slowly into the unused space
+print(len(b), b)