diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-03-26 18:26:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 18:26:05 (GMT) |
commit | 27ee43183437c473725eba00def0ea7647688926 (patch) | |
tree | 3606c5cfd8e3420cf13b0b3c5f6374e5a2b5513f /Parser | |
parent | 48b3ae9e29545891bece874b4c0c0e394fe0f048 (diff) | |
download | cpython-27ee43183437c473725eba00def0ea7647688926.zip cpython-27ee43183437c473725eba00def0ea7647688926.tar.gz cpython-27ee43183437c473725eba00def0ea7647688926.tar.bz2 |
[3.10] bpo-47117: Don't crash if we fail to decode characters when the tokenizer buffers are uninitialized (GH-32129) (GH-32130)
Automerge-Triggered-By: GH:pablogsal.
(cherry picked from commit 26cca8067bf5306e372c0e90036d832c5021fd90)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index df17476..90a6ab9 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -435,7 +435,12 @@ get_error_line(Parser *p, Py_ssize_t lineno) assert((p->tok->fp == NULL && p->tok->str != NULL) || p->tok->fp == stdin); char *cur_line = p->tok->fp_interactive ? p->tok->interactive_src_start : p->tok->str; - assert(cur_line != NULL); + if (cur_line == NULL) { + assert(p->tok->fp_interactive); + // We can reach this point if the tokenizer buffers for interactive source have not been + // initialized because we failed to decode the original source with the given locale. + return PyUnicode_FromStringAndSize("", 0); + } const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp; Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno; @@ -495,7 +500,7 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, goto error; } - if (p->tok->fp_interactive) { + if (p->tok->fp_interactive && p->tok->interactive_src_start != NULL) { error_line = get_error_line(p, lineno); } else if (p->start_rule == Py_file_input) { |