diff options
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index b638592..5dedc1b 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -186,9 +186,23 @@ class ZipFile: else: # file is not a zip file, just append fp.seek(0, 2) else: + if not self._filePassed: + self.fp.close() + self.fp = None raise RuntimeError, 'Mode must be "r", "w" or "a"' def _GetContents(self): + """Read the directory, making sure we close the file if the format + is bad.""" + try: + self._RealGetContents() + except BadZipfile: + if not self._filePassed: + self.fp.close() + self.fp = None + raise + + def _RealGetContents(self): """Read in the table of contents for the ZIP file.""" fp = self.fp fp.seek(-22, 2) # Start of end-of-archive record |