validate bounds of pixel index in make_opaque and is_transparent

This commit is contained in:
foamyguy 2022-06-21 22:11:58 -05:00
parent fcf46552f0
commit 8daa1be701
1 changed files with 8 additions and 0 deletions

View File

@ -179,6 +179,10 @@ STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t pal
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int"));
}
if (palette_index < 0 || (unsigned)palette_index >= common_hal_displayio_palette_get_len(self)) {
mp_raise_IndexError(translate("palette_index out of bounds"));
}
common_hal_displayio_palette_make_opaque(self, palette_index);
return mp_const_none;
}
@ -195,6 +199,10 @@ STATIC mp_obj_t displayio_palette_obj_is_transparent(mp_obj_t self_in, mp_obj_t
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int"));
}
if (palette_index < 0 || (unsigned)palette_index >= common_hal_displayio_palette_get_len(self)) {
mp_raise_IndexError(translate("palette_index out of bounds"));
}
return mp_obj_new_bool(common_hal_displayio_palette_is_transparent(self, palette_index));
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_is_transparent_obj, displayio_palette_obj_is_transparent);