From 5200f5502407045b747b97168b80d63a3cfafd4f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Mar 2015 13:56:25 +0100 Subject: Issue #19428: Handle PyMarshal_Read*() errors in run_pyc_file() Detect also earlier PyMarshal_Read*() errors in zipimport. --- Modules/zipimport.c | 3 +++ Python/pythonrun.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Modules/zipimport.c b/Modules/zipimport.c index f5ac10b..e83214c 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 992a5a3..a8bd024 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); -- cgit v0.12