Commit f64c813d authored by tzickel's avatar tzickel Committed by Petr Viktorin

bpo-25083: Python can sometimes create incorrect .pyc files (GH-8449)

Python 2 never checked for I/O error when reading .py files and
thus could mistake an I/O error for EOF and create incorrect .pyc
files.
This adds an check for this and aborts on an error.
parent ed62e645
......@@ -29,6 +29,7 @@ extern "C" {
#define E_EOFS 23 /* EOF in triple-quoted string */
#define E_EOLS 24 /* EOL in single-quoted string */
#define E_LINECONT 25 /* Unexpected characters after a line continuation */
#define E_IO 26 /* I/O error */
#ifdef __cplusplus
}
......
Adding I/O error checking when reading .py files and aborting importing on
error.
......@@ -1681,6 +1681,11 @@ int
PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
{
int result = tok_get(tok, p_start, p_end);
if (tok->fp && ferror(tok->fp)) {
clearerr(tok->fp);
result = ERRORTOKEN;
tok->done = E_IO;
}
if (tok->decoding_erred) {
result = ERRORTOKEN;
tok->done = E_DECODE;
......
......@@ -1654,6 +1654,9 @@ err_input(perrdetail *err)
Py_XDECREF(tb);
break;
}
case E_IO:
msg = "I/O error while reading";
break;
case E_LINECONT:
msg = "unexpected character after line continuation character";
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment