|
|
cb219e |
commit bcd39b7b9bd3a7f8a6a34410169794a6264a6fed
|
|
|
cb219e |
Author: Victor Stinner <vstinner@redhat.com>
|
|
|
cb219e |
Date: Wed Nov 7 00:45:13 2018 +0100
|
|
|
cb219e |
|
|
|
cb219e |
bpo-25083: Python can sometimes create incorrect .pyc files
|
|
|
cb219e |
|
|
|
cb219e |
Python 2 never checked for I/O error when reading .py files and
|
|
|
cb219e |
thus could mistake an I/O error for EOF and create incorrect .pyc
|
|
|
cb219e |
files. This adds an check for this and aborts on an error.
|
|
|
cb219e |
|
|
|
cb219e |
Patch by tzickel, commit f64c813de84011a84ca21d75a294861a9cc2dfdc.
|
|
|
cb219e |
|
|
|
cb219e |
Resolves: rhbz#1629982
|
|
|
cb219e |
|
|
|
cb219e |
diff --git a/Include/errcode.h b/Include/errcode.h
|
|
|
cb219e |
index becec80..5c5a0f7 100644
|
|
|
cb219e |
--- a/Include/errcode.h
|
|
|
cb219e |
+++ b/Include/errcode.h
|
|
|
cb219e |
@@ -29,6 +29,7 @@ extern "C" {
|
|
|
cb219e |
#define E_EOFS 23 /* EOF in triple-quoted string */
|
|
|
cb219e |
#define E_EOLS 24 /* EOL in single-quoted string */
|
|
|
cb219e |
#define E_LINECONT 25 /* Unexpected characters after a line continuation */
|
|
|
cb219e |
+#define E_IO 26 /* I/O error */
|
|
|
cb219e |
|
|
|
cb219e |
#ifdef __cplusplus
|
|
|
cb219e |
}
|
|
|
cb219e |
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
|
|
|
cb219e |
index ee6313b..0217f2b 100644
|
|
|
cb219e |
--- a/Parser/tokenizer.c
|
|
|
cb219e |
+++ b/Parser/tokenizer.c
|
|
|
cb219e |
@@ -1644,6 +1644,11 @@ int
|
|
|
cb219e |
PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
|
|
|
cb219e |
{
|
|
|
cb219e |
int result = tok_get(tok, p_start, p_end);
|
|
|
cb219e |
+ if (tok->fp && ferror(tok->fp)) {
|
|
|
cb219e |
+ clearerr(tok->fp);
|
|
|
cb219e |
+ result = ERRORTOKEN;
|
|
|
cb219e |
+ tok->done = E_IO;
|
|
|
cb219e |
+ }
|
|
|
cb219e |
if (tok->decoding_erred) {
|
|
|
cb219e |
result = ERRORTOKEN;
|
|
|
cb219e |
tok->done = E_DECODE;
|
|
|
cb219e |
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
|
|
|
cb219e |
index 0b73f3a..9f06236 100644
|
|
|
cb219e |
--- a/Python/pythonrun.c
|
|
|
cb219e |
+++ b/Python/pythonrun.c
|
|
|
cb219e |
@@ -1643,6 +1643,9 @@ err_input(perrdetail *err)
|
|
|
cb219e |
Py_XDECREF(tb);
|
|
|
cb219e |
break;
|
|
|
cb219e |
}
|
|
|
cb219e |
+ case E_IO:
|
|
|
cb219e |
+ msg = "I/O error while reading";
|
|
|
cb219e |
+ break;
|
|
|
cb219e |
case E_LINECONT:
|
|
|
cb219e |
msg = "unexpected character after line continuation character";
|
|
|
cb219e |
break;
|