QUERY · ISSUE
Taking slice of memoryview in Viper function crashes PyBoard
bugpy-core
On a PyBoard v1.1 with firmware 1.13, put the following code into a file:
import micropython
@micropython.viper
def take_memoryview_slice():
ba = bytearray(10)
mv = memoryview(ba)
slice = mv[0:1]
Running take_memoryview_slice() resets the PyBoard.
CANDIDATE · ISSUE
Resizing bytearray with active memoryviews corrupts state and segfaults
bug
Port, board and/or hardware
Unix
MicroPython version
MicroPython v1.27.0-preview.107.gd1607598f on 2025-09-09; linux [GCC 14.2.0] version
Reproduction
import gc
ba = bytearray(b"abcdefghij")
views = [memoryview(ba) for _ in range(4)]
ba[:] = ba + b"X"*256
gc.collect()
for i, mv in enumerate(views):
mv[0:1] = b"Y"
Expected behaviour
Attempting to resize a bytearray that has active memoryview exports should raise a Python exception and must not corrupt the VM or crash.
Observed behaviour
The resize succeeds; existing memoryviews retain stale pointers to the old buffer. After gc.collect() (or later operations), the VM state gets corrupted and the process segfaults in unrelated code paths (e.g., during enumerate, inside mp_load_method_maybe).
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree