diff -r a5a8d255daee Modules/zipimport.c --- a/Modules/zipimport.c Sat Sep 15 05:52:36 2012 +0300 +++ b/Modules/zipimport.c Sat Sep 15 10:20:12 2012 -0300 @@ -868,6 +868,7 @@ PyObject *path; const char *charset; int bootstrap; + int rc = 0; fp = _Py_fopen(archive, "rb"); if (fp == NULL) { @@ -875,7 +876,12 @@ PyErr_Format(ZipImportError, "can't open Zip file: %R", archive); return NULL; } - fseek(fp, -22, SEEK_END); + rc = fseek(fp, -22, SEEK_END); + if (rc == -1) { + fclose(fp); + PyErr_Format(ZipImportError, "can't read Zip file: %R", archive); + return NULL; + } header_position = ftell(fp); if (fread(endof_central_dir, 1, 22, fp) != 22) { fclose(fp); @@ -904,11 +910,15 @@ PyObject *t; int err; - fseek(fp, header_offset, 0); /* Start of file header */ + rc = fseek(fp, header_offset, 0); /* Start of file header */ + if (rc == -1) + goto fseek_error; l = PyMarshal_ReadLongFromFile(fp); if (l != 0x02014B50) break; /* Bad: Central Dir File Header */ - fseek(fp, header_offset + 8, 0); + rc = fseek(fp, header_offset + 8, 0); + if (rc == -1) + goto fseek_error; flags = (unsigned short)PyMarshal_ReadShortFromFile(fp); compress = PyMarshal_ReadShortFromFile(fp); time = PyMarshal_ReadShortFromFile(fp); @@ -920,7 +930,9 @@ header_size = 46 + name_size + PyMarshal_ReadShortFromFile(fp) + PyMarshal_ReadShortFromFile(fp); - fseek(fp, header_offset + 42, 0); + rc = fseek(fp, header_offset + 42, 0); + if (rc == -1) + goto fseek_error; file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset; if (name_size > MAXPATHLEN) name_size = MAXPATHLEN; @@ -980,6 +992,12 @@ PySys_FormatStderr("# zipimport: found %ld names in %R\n", count, archive); return files; +fseek_error: + fclose(fp); + Py_XDECREF(files); + Py_XDECREF(nameobj); + PyErr_Format(ZipImportError, "can't read Zip file: %R", archive); + return NULL; error: fclose(fp); Py_XDECREF(files); @@ -1050,7 +1068,13 @@ } /* Check to make sure the local file header is correct */ - fseek(fp, file_offset, 0); + err = fseek(fp, file_offset, 0); + if (err == -1) { + fclose(fp); + PyErr_Format(ZipImportError, "can't read Zip file: %R", archive); + return NULL; + } + l = PyMarshal_ReadLongFromFile(fp); if (l != 0x04034B50) { /* Bad: Local File Header */ @@ -1060,7 +1084,13 @@ fclose(fp); return NULL; } - fseek(fp, file_offset + 26, 0); + err = fseek(fp, file_offset + 26, 0); + if (err == -1) { + fclose(fp); + PyErr_Format(ZipImportError, "can't read Zip file: %R", archive); + return NULL; + } + l = 30 + PyMarshal_ReadShortFromFile(fp) + PyMarshal_ReadShortFromFile(fp); /* local header size */ file_offset += l; /* Start of file data */ @@ -1077,8 +1107,13 @@ buf = PyBytes_AsString(raw_data); err = fseek(fp, file_offset, 0); - if (err == 0) + if (err == 0) { bytes_read = fread(buf, 1, data_size, fp); + } else { + fclose(fp); + PyErr_Format(ZipImportError, "can't read Zip file: %R", archive); + return NULL; + } fclose(fp); if (err || bytes_read != data_size) { PyErr_SetString(PyExc_IOError,