Core and Builtins
-----------------
+- Issue #19428: zipimport now handles errors when reading truncated or invalid
+ ZIP archive.
+
- Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle
exceptions when merging fast locals into f_locals of a frame.
PyEval_GetLocals() now raises an exception and return NULL on failure.
/* Start of file header */
l = PyMarshal_ReadLongFromFile(fp);
+ if (l == -1 && PyErr_Occurred())
+ goto error;
if (l != 0x02014B50)
break; /* Bad: Central Dir File Header */
if (fread(dummy, 1, 8, fp) != 8) /* Skip unused fields, avoid fseek */
goto file_error;
file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset;
+ if (PyErr_Occurred())
+ goto error;
+
if (name_size > MAXPATHLEN)
name_size = MAXPATHLEN;
l = PyMarshal_ReadLongFromFile(fp);
if (l != 0x04034B50) {
/* Bad: Local File Header */
- PyErr_Format(ZipImportError,
- "bad local file header in %U",
- archive);
+ if (!PyErr_Occurred())
+ PyErr_Format(ZipImportError,
+ "bad local file header in %U",
+ archive);
fclose(fp);
return NULL;
}
l = 30 + PyMarshal_ReadShortFromFile(fp) +
PyMarshal_ReadShortFromFile(fp); /* local header size */
+ if (PyErr_Occurred()) {
+ fclose(fp);
+ return NULL;
+ }
file_offset += l; /* Start of file data */
bytes_size = compress == 0 ? data_size : data_size + 1;