Skip to content

Commit c981c3d

Browse files
committed
Fix tarfile FilterError handling to skip member extraction
In `tarfile` library, FilterError with error_level set to 0 correctly logged a debugging message but did not properly skip extraction of a member. Updates filter functions to return None when a FilterError is seen, as stated in docs.
1 parent 9cdf05b commit c981c3d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/tarfile.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,21 +2309,21 @@ def _get_extract_tarinfo(self, member, filter_function, path):
23092309
else:
23102310
tarinfo = member
23112311

2312-
unfiltered = tarinfo
2312+
filtered = None
23132313
try:
2314-
tarinfo = filter_function(tarinfo, path)
2314+
filtered = filter_function(tarinfo, path)
23152315
except (OSError, FilterError) as e:
23162316
self._handle_fatal_error(e)
23172317
except ExtractError as e:
23182318
self._handle_nonfatal_error(e)
2319-
if tarinfo is None:
2320-
self._dbg(2, "tarfile: Excluded %r" % unfiltered.name)
2319+
if filtered is None:
2320+
self._dbg(2, "tarfile: Excluded %r" % tarinfo.name)
23212321
return None
23222322
# Prepare the link target for makelink().
2323-
if tarinfo.islnk():
2324-
tarinfo = copy.copy(tarinfo)
2325-
tarinfo._link_target = os.path.join(path, tarinfo.linkname)
2326-
return tarinfo
2323+
if filtered.islnk():
2324+
filtered = copy.copy(filtered)
2325+
filtered._link_target = os.path.join(path, filtered.linkname)
2326+
return filtered
23272327

23282328
def _extract_one(self, tarinfo, path, set_attrs, numeric_owner):
23292329
"""Extract from filtered tarinfo to disk"""

0 commit comments

Comments
 (0)