Issue #19428: Handle PyMarshal_Read*() errors in run_pyc_file()
Detect also earlier PyMarshal_Read*() errors in zipimport.
This commit is contained in:
parent
50931f41d0
commit
5200f55024
|
@ -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;
|
||||
|
|
|
@ -981,6 +981,7 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals,
|
|||
|
||||
magic = PyMarshal_ReadLongFromFile(fp);
|
||||
if (magic != PyImport_GetMagicNumber()) {
|
||||
if (!PyErr_Occurred())
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"Bad magic number in .pyc file");
|
||||
return NULL;
|
||||
|
@ -988,6 +989,9 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals,
|
|||
/* 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);
|
||||
|
|
Loading…
Reference in New Issue