diff --git a/Modules/zipimport.c b/Modules/zipimport.c index f5ac10beb0b..e83214c16cf 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -939,6 +939,9 @@ read_directory(PyObject *archive) header_size = name_size + PyMarshal_ReadShortFromFile(fp) + PyMarshal_ReadShortFromFile(fp); + if (PyErr_Occurred()) + goto error; + if (fread(dummy, 1, 8, fp) != 8) /* Skip unused fields, avoid fseek */ goto file_error; file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 992a5a3ed09..a8bd02440f5 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -981,13 +981,17 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals, magic = PyMarshal_ReadLongFromFile(fp); if (magic != PyImport_GetMagicNumber()) { - PyErr_SetString(PyExc_RuntimeError, - "Bad magic number in .pyc file"); + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, + "Bad magic number in .pyc file"); return NULL; } /* Skip mtime and size */ (void) PyMarshal_ReadLongFromFile(fp); (void) PyMarshal_ReadLongFromFile(fp); + if (PyErr_Occurred()) + return NULL; + v = PyMarshal_ReadLastObjectFromFile(fp); if (v == NULL || !PyCode_Check(v)) { Py_XDECREF(v);