Skip to content

Commit 5828105

Browse files
Use extract_path (not CWD) as tar-extraction containment base
The pre-3.12 fallback in custom_extractall_tarfile filtered members with _get_safe_members, which resolved its containment base from the current working directory (_get_resolved_path("")) instead of the extraction target. A crafted model/code tarball could therefore write outside the intended extract_path; the post-extraction validator only walks extract_path and cannot see escapes. Pass extract_path into _get_safe_members so members are validated against the extraction target, matching _validate_extracted_paths and the _repack_model.py sibling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a15a449 commit 5828105

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

sagemaker-core/src/sagemaker/core/common_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ def _is_bad_link(info, base):
17671767
return _is_bad_path(info.linkname, base=tip)
17681768

17691769

1770-
def _get_safe_members(members):
1770+
def _get_safe_members(members, base_path):
17711771
"""A generator that yields members that are safe to extract.
17721772
17731773
It filters out bad paths and bad links.
@@ -1778,7 +1778,7 @@ def _get_safe_members(members):
17781778
Yields:
17791779
tarfile.TarInfo: The tar file info.
17801780
"""
1781-
base = _get_resolved_path("")
1781+
base = _get_resolved_path(base_path)
17821782

17831783
for file_info in members:
17841784
if _is_bad_path(file_info.name, base):
@@ -1842,7 +1842,7 @@ def custom_extractall_tarfile(tar, extract_path):
18421842
if hasattr(tarfile, "data_filter"):
18431843
tar.extractall(path=extract_path, filter="data")
18441844
else:
1845-
tar.extractall(path=extract_path, members=_get_safe_members(tar))
1845+
tar.extractall(path=extract_path, members=_get_safe_members(tar, extract_path))
18461846
# Re-validate extracted paths to catch symlink race conditions
18471847
_validate_extracted_paths(extract_path)
18481848

0 commit comments

Comments
 (0)