summaryrefslogtreecommitdiffstats
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-10-29 00:43:44 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-10-29 00:43:44 (GMT)
commit73660af6afdd8309c85d5e513e319b7f0a5b006e (patch)
tree9a0e56bb8acdf8de501fd6230cc6e618058adf8b /Modules/zipimport.c
parenta5afb58986cc0cd63908f1b5b44d472611f67b4f (diff)
downloadcpython-73660af6afdd8309c85d5e513e319b7f0a5b006e.zip
cpython-73660af6afdd8309c85d5e513e319b7f0a5b006e.tar.gz
cpython-73660af6afdd8309c85d5e513e319b7f0a5b006e.tar.bz2
Issue #19428: zipimport now handles errors when reading truncated or invalid
ZIP archive.
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 633732f..46b86a0 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -914,6 +914,8 @@ read_directory(PyObject *archive)
/* Start of file header */
l = PyMarshal_ReadLongFromFile(fp);
+ if (l == -1 && PyErr_Occurred())
+ goto error;
if (l != 0x02014B50)
break; /* Bad: Central Dir File Header */
@@ -937,6 +939,9 @@ read_directory(PyObject *archive)
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;
@@ -1082,9 +1087,10 @@ get_data(PyObject *archive, PyObject *toc_entry)
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;
}
@@ -1096,6 +1102,10 @@ get_data(PyObject *archive, PyObject *toc_entry)
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;