Skip to content

Commit 0220b82

Browse files
authored
Merge pull request #68 from ActiveState/BE-3659-cve-2007-4559-IIII
Be 3659 CVE 2007 4559 iiii
2 parents 8701d6c + a7c09b5 commit 0220b82

File tree

4 files changed

+358
-5
lines changed

4 files changed

+358
-5
lines changed

Lib/tarfile.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,22 @@ def __iter__(self):
916916
if not line:
917917
break
918918
yield line
919+
920+
def __enter__(self):
921+
#INFO: This was used in Python3.6, but we aren't based off io.BufferedReader in Python2
922+
# self._check()
923+
return self
924+
925+
def __exit__(self, type, value, traceback):
926+
if type is None:
927+
self.close()
928+
else:
929+
# An exception occurred. We must not call close() because
930+
# it would try to write end-of-archive blocks and padding.
931+
if not self._extfileobj:
932+
self.fileobj.close()
933+
934+
919935
#class ExFileObject
920936

921937
#------------------
@@ -1946,14 +1962,16 @@ def gettarinfo(self, name=None, arcname=None, fileobj=None):
19461962
tarinfo.devminor = os.minor(statres.st_rdev)
19471963
return tarinfo
19481964

1949-
def list(self, verbose=True):
1965+
def list(self, verbose=True, members=None):
19501966
"""Print a table of contents to sys.stdout. If `verbose' is False, only
19511967
the names of the members are printed. If it is True, an `ls -l'-like
19521968
output is produced.
19531969
"""
19541970
self._check()
19551971

1956-
for tarinfo in self:
1972+
if members is None:
1973+
members = self.getmembers()
1974+
for tarinfo in members:
19571975
if verbose:
19581976
print filemode(tarinfo.mode),
19591977
print "%s/%s" % (tarinfo.uname or tarinfo.uid,

0 commit comments

Comments
 (0)