From 330517bde9d7b6a78583e42dfdf585118db40dfb Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 15:39:07 -0700 Subject: [PATCH 1/6] Validate portions of mpy load to detect corruption Fixes #1917 --- py/persistentcode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/py/persistentcode.c b/py/persistentcode.c index f6de782ed8..c0358faa02 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -128,6 +128,12 @@ STATIC qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); char str[len]; read_bytes(reader, (byte*)str, len); + // Validate the QSTRs by ensuring they do not contain any null terminations. They are length encoded instead. + for (size_t i = 0; i < len; i++) { + if (str[i] == '\0') { + mp_raise_RuntimeError(translate("Corrupt .mpy file")); + } + } qstr qst = qstr_from_strn(str, len); return qst; } @@ -145,11 +151,12 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { return mp_obj_new_str_from_vstr(obj_type == 's' ? &mp_type_str : &mp_type_bytes, &vstr); } else if (obj_type == 'i') { return mp_parse_num_integer(vstr.buf, vstr.len, 10, NULL); - } else { - assert(obj_type == 'f' || obj_type == 'c'); + } else if (obj_type == 'f' || obj_type == 'c') { return mp_parse_num_decimal(vstr.buf, vstr.len, obj_type == 'c', false, NULL); } } + mp_raise_RuntimeError(translate("Corrupt .mpy file")); + return MP_OBJ_FROM_PTR(&mp_const_none_obj); } STATIC void load_bytecode_qstrs(mp_reader_t *reader, byte *ip, byte *ip_top) { From 77355cbb2f5a3cc2b48468955774a830f18ecf39 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 16:52:52 -0700 Subject: [PATCH 2/6] Update translations --- locale/ID.po | 6 +++++- locale/circuitpython.pot | 6 +++++- locale/de_DE.po | 6 +++++- locale/en_US.po | 6 +++++- locale/en_x_pirate.po | 6 +++++- locale/es.po | 6 +++++- locale/fil.po | 6 +++++- locale/fr.po | 6 +++++- locale/it_IT.po | 6 +++++- locale/pl.po | 6 +++++- locale/pt_BR.po | 6 +++++- locale/zh_Latn_pinyin.po | 6 +++++- 12 files changed, 60 insertions(+), 12 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index f5c0c09495..9545845cd9 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -460,6 +460,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 34070dc69b..7e9f655817 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:41-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -450,6 +450,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/de_DE.po b/locale/de_DE.po index 2cb97c3d31..5e948cb6b6 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -454,6 +454,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_US.po b/locale/en_US.po index ebc18cfaee..a50263d9fe 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -450,6 +450,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 04706abdcd..443204fb57 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -454,6 +454,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/es.po b/locale/es.po index 77739f49cb..2135b7e77f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -466,6 +466,10 @@ msgstr "La entrada en la columna debe ser digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Bytes debe estar entre 0 y 255." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fil.po b/locale/fil.po index 5954e29b49..8f3996d16a 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -459,6 +459,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fr.po b/locale/fr.po index 0bd0f8771e..6ee7b4d5a1 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -465,6 +465,10 @@ msgstr "L'entrée 'Column' doit être un digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "La commande doit être un entier entre 0 et 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/it_IT.po b/locale/it_IT.po index 12f21c38ea..ef1e306a1e 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -460,6 +460,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pl.po b/locale/pl.po index 1a7471f728..09187eb671 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -453,6 +453,10 @@ msgstr "Kolumny muszą być typu digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Komenda musi być int pomiędzy 0 a 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 390610041e..734491dd75 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -456,6 +456,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 82264cb526..8ad03c968f 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -454,6 +454,10 @@ msgstr "Liè tiáomù bìxū shì digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" From 2494bfdc8626aadb7d3197d165daf2569f3a8db1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 17:54:27 -0700 Subject: [PATCH 3/6] Validate raw code and mpy read length --- locale/ID.po | 6 +++++- locale/circuitpython.pot | 6 +++++- locale/de_DE.po | 6 +++++- locale/en_US.po | 6 +++++- locale/en_x_pirate.po | 6 +++++- locale/es.po | 6 +++++- locale/fil.po | 6 +++++- locale/fr.po | 6 +++++- locale/it_IT.po | 6 +++++- locale/pl.po | 6 +++++- locale/pt_BR.po | 6 +++++- locale/zh_Latn_pinyin.po | 6 +++++- py/emitglue.c | 7 ++++--- py/persistentcode.c | 29 +++++++++++++++++++---------- 14 files changed, 83 insertions(+), 25 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 9545845cd9..60d882bc60 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -464,6 +464,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 7e9f655817..1c48658ec7 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -454,6 +454,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/de_DE.po b/locale/de_DE.po index 5e948cb6b6..2b3b25ce7c 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -458,6 +458,10 @@ msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_US.po b/locale/en_US.po index a50263d9fe..1b5c360109 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -454,6 +454,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 443204fb57..12a134a7dc 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -458,6 +458,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/es.po b/locale/es.po index 2135b7e77f..63dae87de0 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -470,6 +470,10 @@ msgstr "Bytes debe estar entre 0 y 255." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fil.po b/locale/fil.po index 8f3996d16a..393c67ad13 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -463,6 +463,10 @@ msgstr "Sa gitna ng 0 o 255 dapat ang bytes." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fr.po b/locale/fr.po index 6ee7b4d5a1..a64deeace7 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -469,6 +469,10 @@ msgstr "La commande doit être un entier entre 0 et 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/it_IT.po b/locale/it_IT.po index ef1e306a1e..52c229e030 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -464,6 +464,10 @@ msgstr "I byte devono essere compresi tra 0 e 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pl.po b/locale/pl.po index 09187eb671..bdb6f47958 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -457,6 +457,10 @@ msgstr "Komenda musi być int pomiędzy 0 a 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 734491dd75..8b61c23b81 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -460,6 +460,10 @@ msgstr "Os bytes devem estar entre 0 e 255." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 8ad03c968f..314591560a 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -458,6 +458,10 @@ msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/py/emitglue.c b/py/emitglue.c index 74bf8ddca2..7708689dd4 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -142,11 +142,12 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->data.u_native.fun_data, rc->data.u_native.type_sig); break; #endif - default: - // rc->kind should always be set and BYTECODE is the only remaining case - assert(rc->kind == MP_CODE_BYTECODE); + case MP_CODE_BYTECODE: fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->data.u_byte.bytecode, rc->data.u_byte.const_table); break; + default: + // All other kinds are invalid. + mp_raise_RuntimeError(translate("Corrupt raw code")); } // check for generator functions and if so wrap in generator object diff --git a/py/persistentcode.c b/py/persistentcode.c index c0358faa02..eb69bd4079 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -102,20 +102,35 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_ #include "py/parsenum.h" +STATIC void raise_corrupt_mpy(void) { + mp_raise_RuntimeError(translate("Corrupt .mpy file")); +} + STATIC int read_byte(mp_reader_t *reader) { - return reader->readbyte(reader->data); + mp_uint_t b = reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } + return b; } STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { while (len-- > 0) { - *buf++ = reader->readbyte(reader->data); + mp_uint_t b =reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } + *buf++ = b; } } STATIC size_t read_uint(mp_reader_t *reader) { size_t unum = 0; for (;;) { - byte b = reader->readbyte(reader->data); + mp_uint_t b = reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } unum = (unum << 7) | (b & 0x7f); if ((b & 0x80) == 0) { break; @@ -128,12 +143,6 @@ STATIC qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); char str[len]; read_bytes(reader, (byte*)str, len); - // Validate the QSTRs by ensuring they do not contain any null terminations. They are length encoded instead. - for (size_t i = 0; i < len; i++) { - if (str[i] == '\0') { - mp_raise_RuntimeError(translate("Corrupt .mpy file")); - } - } qstr qst = qstr_from_strn(str, len); return qst; } @@ -155,7 +164,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { return mp_parse_num_decimal(vstr.buf, vstr.len, obj_type == 'c', false, NULL); } } - mp_raise_RuntimeError(translate("Corrupt .mpy file")); + raise_corrupt_mpy(); return MP_OBJ_FROM_PTR(&mp_const_none_obj); } From 6d2072f9cb3385eb6d69ac876d9d415a4e41e062 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 11:02:18 -0700 Subject: [PATCH 4/6] Fix tests --- tests/import/mpy_invalid.py | 4 ++-- tests/import/mpy_invalid.py.exp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/import/mpy_invalid.py b/tests/import/mpy_invalid.py index 6a4e116e78..b9dd99a440 100644 --- a/tests/import/mpy_invalid.py +++ b/tests/import/mpy_invalid.py @@ -59,8 +59,8 @@ for i in range(len(user_files)): mod = 'mod%u' % i try: __import__(mod) - except ValueError as er: - print(mod, 'ValueError', er) + except Exception as e: + print(mod, type(e).__name__, e) # unmount and undo path addition uos.umount('/userfs') diff --git a/tests/import/mpy_invalid.py.exp b/tests/import/mpy_invalid.py.exp index e4f2b13e99..197eb4f7b2 100644 --- a/tests/import/mpy_invalid.py.exp +++ b/tests/import/mpy_invalid.py.exp @@ -1,3 +1,3 @@ -mod0 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. -mod1 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. -mod2 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. +mod0 RuntimeError Corrupt .mpy file +mod1 RuntimeError Corrupt .mpy file +mod2 MpyError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. From 1f105e0ac0313be9752f68c664c145ca5156a1e9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 15:10:51 -0700 Subject: [PATCH 5/6] Update frozen libraries to save space --- frozen/Adafruit_CircuitPython_BusDevice | 2 +- frozen/Adafruit_CircuitPython_CircuitPlayground | 2 +- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_Motor | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- frozen/circuitpython-stage | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice index 182eebdc81..b9280af514 160000 --- a/frozen/Adafruit_CircuitPython_BusDevice +++ b/frozen/Adafruit_CircuitPython_BusDevice @@ -1 +1 @@ -Subproject commit 182eebdc8168e3d14cd0cb28db3abb734c9e45f3 +Subproject commit b9280af5142fc41639229544678e23b5cca07c3a diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index 0cc2e975ed..154b74de02 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit 0cc2e975ed22ace0d679c6fb8f3388034b88bcf1 +Subproject commit 154b74de020764597ba49f0d1e8cc18d55b3643b diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index c9e07857dc..89faee0eb0 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit c9e07857dc10ff5e6c743e5e8c00e9b049800d09 +Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index f5892e24f7..bd7ddc67dc 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit f5892e24f7235c4bde2908cbb3cd0a3d6b34d421 +Subproject commit bd7ddc67dc86f7ad0115f58ab80d5605739c6482 diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor index 5a50830814..ddc7484498 160000 --- a/frozen/Adafruit_CircuitPython_Motor +++ b/frozen/Adafruit_CircuitPython_Motor @@ -1 +1 @@ -Subproject commit 5a50830814aaeeb1fda34ed0ba2f8397415d9796 +Subproject commit ddc74844983b35b027bd45091c7b8bb3c8d7a2d1 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 4b101f0032..f1171f9408 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 4b101f00320d36b23f8cc28cf3f12127085894c1 +Subproject commit f1171f94083ba64d153ff3f90eeb07500331d6e1 diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index 397badae58..6d1ae72916 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit 397badae5863a1ce932213ef527e82314ac498a1 +Subproject commit 6d1ae72916cf240ea86185c45f844d59f56d8ec3 From fe507db45f7fa21c6de4aafb288a7f83d9903f71 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 16:49:23 -0700 Subject: [PATCH 6/6] Shrink pIRkey build down. Rollback HID to save string space and remove board mapping for default buses that don't exist. --- frozen/Adafruit_CircuitPython_HID | 2 +- ports/atmel-samd/boards/pirkey_m0/pins.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 89faee0eb0..c9e07857dc 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d +Subproject commit c9e07857dc10ff5e6c743e5e8c00e9b049800d09 diff --git a/ports/atmel-samd/boards/pirkey_m0/pins.c b/ports/atmel-samd/boards/pirkey_m0/pins.c index e1f43c83cc..41d02e3291 100644 --- a/ports/atmel-samd/boards/pirkey_m0/pins.c +++ b/ports/atmel-samd/boards/pirkey_m0/pins.c @@ -5,8 +5,5 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);