Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 637431b

Browse files
committed
Patch #1103407: Properly deal with tarfile iterators when untarring
symbolic links on Windows. Fixes #1100429. Will backport to 2.4.
1 parent c9f8525 commit 637431b

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

Lib/tarfile.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,7 @@ def __init__(self, tarfile):
18511851
"""Construct a TarIter object.
18521852
"""
18531853
self.tarfile = tarfile
1854+
self.index = 0
18541855
def __iter__(self):
18551856
"""Return iterator object.
18561857
"""
@@ -1859,10 +1860,20 @@ def next(self):
18591860
"""Return the next item using TarFile's next() method.
18601861
When all members have been read, set TarFile as _loaded.
18611862
"""
1862-
tarinfo = self.tarfile.next()
1863-
if not tarinfo:
1864-
self.tarfile._loaded = True
1865-
raise StopIteration
1863+
# Fix for SF #1100429: Under rare circumstances it can
1864+
# happen that getmembers() is called during iteration,
1865+
# which will cause TarIter to stop prematurely.
1866+
if not self.tarfile._loaded:
1867+
tarinfo = self.tarfile.next()
1868+
if not tarinfo:
1869+
self.tarfile._loaded = True
1870+
raise StopIteration
1871+
else:
1872+
try:
1873+
tarinfo = self.tarfile.members[self.index]
1874+
except IndexError:
1875+
raise StopIteration
1876+
self.index += 1
18661877
return tarinfo
18671878

18681879
# Helper classes for sparse file support

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Extension Modules
7272
Library
7373
-------
7474

75+
- Patch #1103407: Properly deal with tarfile iterators when untarring
76+
symbolic links on Windows.
77+
7578
- Patch #645894: Use getrusage for computing the time consumption in
7679
profile.py if available.
7780

0 commit comments

Comments
 (0)