Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/errcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adding I/O error checking when reading .py files and aborting importing on
error.
5 changes: 5 additions & 0 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down