diff options
Diffstat (limited to 'lib-python/3/tarfile.py')
-rwxr-xr-x | lib-python/3/tarfile.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib-python/3/tarfile.py b/lib-python/3/tarfile.py index edd31e96fb..3be5188c8b 100755 --- a/lib-python/3/tarfile.py +++ b/lib-python/3/tarfile.py @@ -1233,6 +1233,8 @@ class TarInfo(object): length, keyword = match.groups() length = int(length) + if length == 0: + raise InvalidHeaderError("invalid header") value = buf[match.end(2) + 1:match.start(1) + length - 1] # Normally, we could just use "utf-8" as the encoding and "strict" @@ -1629,13 +1631,12 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - import gzip - gzip.GzipFile - except (ImportError, AttributeError): + from gzip import GzipFile + except ImportError: raise CompressionError("gzip module is not available") try: - fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj) + fileobj = GzipFile(name, mode + "b", compresslevel, fileobj) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") @@ -1663,12 +1664,11 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - import bz2 + from bz2 import BZ2File except ImportError: raise CompressionError("bz2 module is not available") - fileobj = bz2.BZ2File(fileobj or name, mode, - compresslevel=compresslevel) + fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel) try: t = cls.taropen(name, mode, fileobj, **kwargs) @@ -1692,15 +1692,15 @@ class TarFile(object): raise ValueError("mode must be 'r', 'w' or 'x'") try: - import lzma + from lzma import LZMAFile, LZMAError except ImportError: raise CompressionError("lzma module is not available") - fileobj = lzma.LZMAFile(fileobj or name, mode, preset=preset) + fileobj = LZMAFile(fileobj or name, mode, preset=preset) try: t = cls.taropen(name, mode, fileobj, **kwargs) - except (lzma.LZMAError, EOFError): + except (LZMAError, EOFError): fileobj.close() if mode == 'r': raise ReadError("not an lzma file") |