Commit f4a12dca authored by Damien George's avatar Damien George

py/objarray: Disallow slice-assignment to read-only memoryview.

Also comes with a test for this.  Fixes issue #2904.
parent 23ccb3e1
...@@ -418,6 +418,10 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value ...@@ -418,6 +418,10 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
uint8_t* dest_items = o->items; uint8_t* dest_items = o->items;
#if MICROPY_PY_BUILTINS_MEMORYVIEW #if MICROPY_PY_BUILTINS_MEMORYVIEW
if (o->base.type == &mp_type_memoryview) { if (o->base.type == &mp_type_memoryview) {
if ((o->typecode & 0x80) == 0) {
// store to read-only memoryview not allowed
return MP_OBJ_NULL;
}
if (len_adj != 0) { if (len_adj != 0) {
goto compat_error; goto compat_error;
} }
......
...@@ -18,6 +18,10 @@ try: ...@@ -18,6 +18,10 @@ try:
m[0] = 1 m[0] = 1
except TypeError: except TypeError:
print("TypeError") print("TypeError")
try:
m[0:2] = b'00'
except TypeError:
print("TypeError")
# test writing to bytearray # test writing to bytearray
b = bytearray(b) b = bytearray(b)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment