From 7af168ff8173d0a0a69bd54dc87768808b02a9ea Mon Sep 17 00:00:00 2001 From: Greg Ward Date: Wed, 18 Jun 2003 01:05:34 +0000 Subject: [PATCH] Patch #755987 (bug #755031): backport from trunk. --- Lib/zipfile.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 0efcad3a8a4f..9e8f60abc2ab 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1,6 +1,4 @@ "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 import binascii @@ -92,7 +90,18 @@ class ZipInfo: """Class with attributes describing each file in the ZIP archive.""" 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.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] +# 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: self.compress_type = ZIP_STORED # Type of compression for the file @@ -133,17 +142,6 @@ class ZipInfo: return header + self.filename + self.extra -# 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. @@ -281,10 +279,10 @@ class ZipFile: + fheader[_FH_FILENAME_LENGTH] + fheader[_FH_EXTRA_FIELD_LENGTH]) fname = fp.read(fheader[_FH_FILENAME_LENGTH]) - if fname != data.filename: + if fname != data.orig_filename: raise RuntimeError, \ 'File name in directory "%s" and header "%s" differ.' % ( - data.filename, fname) + data.orig_filename, fname) def namelist(self): """Return a list of file names in the archive.""" -- 2.47.3