← index #1710PR #14029
Related · high · value 0.732
QUERY · ISSUE

bytearray slice assignment fails for derived types

openby mbueschopened 2015-12-11updated 2024-08-28
docs

The type check for slice assignment to bytearray derived types seems to be a bit too strict:

class MyBytearray(bytearray): pass

a = MyBytearray(4)
b = MyBytearray(4)
a[0:4] = b

results in this error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
NotImplementedError: array/bytes required on right side
CANDIDATE · PULL REQUEST

py/objarray: Fix use-after-free if extending a slice from itself.

mergedby projectgusopened 2024-03-05updated 2024-11-01
bugpy-core

Closes https://github.com/micropython/micropython/issues/13283 which reported this bug when assigning to a slice, also fixes a related bug when a bytearray is extended by itself (h/t @dpgeorge for spotting.) Unit tests added for both.

There is a related much more nefarious set of bugs when a bytearray or similar is targeted by a memoryview and then resized. For now these are not fixed, but have pushed a commit here to document this case as a difference from CPython.

Reproducing this bug and confirming the fix was done by running the unix port under valgrind with GC-aware extensions (PR at https://github.com/micropython/micropython/pull/14196).

Note in default configurations with GIL this bug exists but has no impact (the free buffer won't have new data written to it while the function is still executing, and is no longer referenced after the function returns).

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied