[Python-checkins] python/dist/src/Lib zipfile.py,1.28,1.29
gward@users.sourceforge.net
gward@users.sourceforge.net
Tue, 17 Jun 2003 17:53:08 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv21153/Lib
Modified Files:
zipfile.py
Log Message:
SF patch #755987 (Jim Ahlstrom):
This is a patch for Bug 755031: If a null byte appears in
a file name, Python zipfile.py retains it, but InfoZip
terminates the name. Null bytes in file names are used
as a trick by viruses. I tested WinZip, and it also
truncates the file name at the null byte.
The patch also fixes a buglet: If a zipfile incorrectly
uses a directory separator other than '/', there was an
invalid complaint that the central directory name does
not match the file header name.
I also removed my name from the top of the file. It was
there for legal reasons which I believe no longer apply.
Many people have worked on this file besides me.
Index: zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/zipfile.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** zipfile.py 15 Jan 2003 11:51:06 -0000 1.28
--- zipfile.py 18 Jun 2003 00:53:06 -0000 1.29
***************
*** 1,5 ****
"Read and write ZIP files."
- # Written by James C. Ahlstrom jim@interet.com
- # All rights transferred to CNRI pursuant to the Python contribution agreement
import struct, os, time
--- 1,3 ----
***************
*** 117,121 ****
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
! self.filename = _normpath(filename) # Name of the file in the archive
self.date_time = date_time # year, month, day, hour, min, sec
# Standard values:
--- 115,131 ----
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
! self.orig_filename = filename # Original file name in archive
! # Terminate the file name at the first null byte. Null bytes in file
! # names are used as tricks by viruses in archives.
! null_byte = filename.find(chr(0))
! if null_byte >= 0:
! filename = filename[0:null_byte]
! print "File name %s contains a suspicious null byte!" % filename
! # This is used to ensure paths in generated ZIP files always use
! # forward slashes as the directory separator, as required by the
! # ZIP format specification.
! if os.sep != "/":
! filename = filename.replace(os.sep, "/")
! self.filename = filename # Normalized file name
self.date_time = date_time # year, month, day, hour, min, sec
# Standard values:
***************
*** 158,172 ****
- # This is used to ensure paths in generated ZIP files always use
- # forward slashes as the directory separator, as required by the
- # ZIP format specification.
- if os.sep != "/":
- def _normpath(path):
- return path.replace(os.sep, "/")
- else:
- def _normpath(path):
- return path
-
-
class ZipFile:
""" Class with methods to open, read, write, close, list zip files.
--- 168,171 ----
***************
*** 301,308 ****
+ fheader[_FH_EXTRA_FIELD_LENGTH])
fname = fp.read(fheader[_FH_FILENAME_LENGTH])
! if fname != data.filename:
raise RuntimeError, \
'File name in directory "%s" and header "%s" differ.' % (
! data.filename, fname)
def namelist(self):
--- 300,307 ----
+ fheader[_FH_EXTRA_FIELD_LENGTH])
fname = fp.read(fheader[_FH_FILENAME_LENGTH])
! if fname != data.orig_filename:
raise RuntimeError, \
'File name in directory "%s" and header "%s" differ.' % (
! data.orig_filename, fname)
def namelist(self):