validate bounds of pixel index in make_transparent

This commit is contained in:
foamyguy 2022-06-21 22:03:59 -05:00
parent 562c73bcc7
commit fcf46552f0
2 changed files with 10 additions and 7 deletions

View File

@ -72,7 +72,7 @@ msgstr ""
#: ports/mimxrt10xx/common-hal/rtc/RTC.c
#: ports/nrf/common-hal/analogio/AnalogOut.c ports/nrf/common-hal/rtc/RTC.c
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
#: ports/raspberrypi/common-hal/rtc/RTC.c
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/rtc/RTC.c
msgid "%q"
msgstr ""
@ -432,7 +432,6 @@ msgstr ""
msgid "All event channels in use"
msgstr ""
#: ports/raspberrypi/common-hal/pulseio/PulseIn.c
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "All state machines in use"
msgstr ""
@ -518,7 +517,7 @@ msgstr ""
msgid "AuthMode.OPEN is not used with password"
msgstr ""
#: shared-bindings/wifi/Radio.c
#: shared-bindings/wifi/Radio.c supervisor/shared/web_workflow/web_workflow.c
msgid "Authentication failure"
msgstr ""
@ -3687,6 +3686,10 @@ msgstr ""
msgid "palette must be 32 bytes long"
msgstr ""
#: shared-bindings/displayio/Palette.c
msgid "palette_index out of bounds"
msgstr ""
#: shared-bindings/displayio/Palette.c
msgid "palette_index should be an int"
msgstr ""
@ -3915,10 +3918,6 @@ msgstr ""
msgid "source_bitmap must have value_count of 8"
msgstr ""
#: shared-bindings/wifi/Radio.c
msgid "ssid can't be more than 32 bytes"
msgstr ""
#: py/objstr.c
msgid "start/end indices"
msgstr ""

View File

@ -160,6 +160,10 @@ STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_
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_transparent(self, palette_index);
return mp_const_none;
}