Zip file reading: Be more tolerant when a zip file has a damaged directory

This commit is contained in:
Kovid Goyal 2011-01-12 17:46:35 -07:00
parent 7fde6cbead
commit ee246b73ec

View File

@ -982,9 +982,12 @@ class ZipFile:
zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH]) zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH])
if fname != zinfo.orig_filename: if fname != zinfo.orig_filename:
raise BadZipfile, \ print ('WARNING: Header (%r) and directory (%r) filenames do not'
'File name in directory "%s" and header "%s" differ.' % ( ' match inside ZipFile')%(fname, zinfo.orig_filename)
zinfo.orig_filename, fname) print 'Using directory filename %r'%zinfo.orig_filename
#raise BadZipfile, \
# 'File name in directory "%r" and header "%r" differ.' % (
# zinfo.orig_filename, fname)
# check for encrypted flag & handle password # check for encrypted flag & handle password
is_encrypted = zinfo.flag_bits & 0x1 is_encrypted = zinfo.flag_bits & 0x1