summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2003-07-22 18:10:15 (GMT)
committerThomas Heller <theller@ctypes.org>2003-07-22 18:10:15 (GMT)
commit354e3d90d346afdc6c70211b130aa76bb18e19ed (patch)
treee03da58869310f187315670c86523d4ce4b69763 /Modules
parentfac083d14a94137999559d895a4e6d1d9a2ea74c (diff)
downloadcpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.zip
cpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.tar.gz
cpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.tar.bz2
Change the zipimport implementation to accept files containing
arbitrary bytes before the actual zip compatible archive. Zipfiles containing comments at the end of the file are still not supported. Add a testcase to test_zipimport, and update NEWS. This closes sf #775637 and sf #669036.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zipimport.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 1c95d5a..afcd421 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -655,11 +655,12 @@ read_directory(char *archive)
PyObject *files = NULL;
FILE *fp;
long compress, crc, data_size, file_size, file_offset, date, time;
- long header_offset, name_size, header_size;
+ long header_offset, name_size, header_size, header_position;
long i, l, length, count;
char path[MAXPATHLEN + 5];
char name[MAXPATHLEN + 5];
char *p, endof_central_dir[22];
+ long arc_offset; /* offset from beginning of file to start of zip-archive */
if (strlen(archive) > MAXPATHLEN) {
PyErr_SetString(PyExc_OverflowError,
@@ -675,6 +676,7 @@ read_directory(char *archive)
return NULL;
}
fseek(fp, -22, SEEK_END);
+ header_position = ftell(fp);
if (fread(endof_central_dir, 1, 22, fp) != 22) {
fclose(fp);
PyErr_Format(ZipImportError, "can't read Zip file: "
@@ -689,7 +691,10 @@ read_directory(char *archive)
return NULL;
}
+ header_size = get_long((unsigned char *)endof_central_dir + 12);
header_offset = get_long((unsigned char *)endof_central_dir + 16);
+ arc_offset = header_position - header_offset - header_size;
+ header_offset += arc_offset;
files = PyDict_New();
if (files == NULL)
@@ -720,7 +725,7 @@ read_directory(char *archive)
PyMarshal_ReadShortFromFile(fp) +
PyMarshal_ReadShortFromFile(fp);
fseek(fp, header_offset + 42, 0);
- file_offset = PyMarshal_ReadLongFromFile(fp);
+ file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset;
if (name_size > MAXPATHLEN)
name_size = MAXPATHLEN;