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); }