[Python-checkins] python/dist/src/Modules zipimport.c,1.15,1.16
theller@users.sourceforge.net
theller@users.sourceforge.net
Tue, 22 Jul 2003 11:10:17 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv9458
Modified Files:
zipimport.c
Log Message:
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.
Index: zipimport.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/zipimport.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** zipimport.c 17 Jul 2003 15:56:07 -0000 1.15
--- zipimport.c 22 Jul 2003 18:10:15 -0000 1.16
***************
*** 656,664 ****
FILE *fp;
long compress, crc, data_size, file_size, file_offset, date, time;
! long header_offset, name_size, header_size;
long i, l, length, count;
char path[MAXPATHLEN + 5];
char name[MAXPATHLEN + 5];
char *p, endof_central_dir[22];
if (strlen(archive) > MAXPATHLEN) {
--- 656,665 ----
FILE *fp;
long compress, crc, data_size, file_size, file_offset, date, time;
! 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) {
***************
*** 676,679 ****
--- 677,681 ----
}
fseek(fp, -22, SEEK_END);
+ header_position = ftell(fp);
if (fread(endof_central_dir, 1, 22, fp) != 22) {
fclose(fp);
***************
*** 690,694 ****
--- 692,699 ----
}
+ 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();
***************
*** 721,725 ****
PyMarshal_ReadShortFromFile(fp);
fseek(fp, header_offset + 42, 0);
! file_offset = PyMarshal_ReadLongFromFile(fp);
if (name_size > MAXPATHLEN)
name_size = MAXPATHLEN;
--- 726,730 ----
PyMarshal_ReadShortFromFile(fp);
fseek(fp, header_offset + 42, 0);
! file_offset = PyMarshal_ReadLongFromFile(fp) + arc_offset;
if (name_size > MAXPATHLEN)
name_size = MAXPATHLEN;