Skip to content

Commit d977202

Browse files
authored
Merge pull request #14 from TrellixVulnTeam/master
CVE-2007-4559 Patch
2 parents 73982d2 + feabc1f commit d977202

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

TESTS/unitTests.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,25 @@ def main():
14601460
if total_size != 0 and wrote != total_size:
14611461
raise Exception("Error downloading test matfiles!")
14621462
with tarfile.open(matfiles_path + ".tar.gz") as f:
1463-
f.extractall(os.path.dirname(matfiles_path))
1463+
def is_within_directory(directory, target):
1464+
1465+
abs_directory = os.path.abspath(directory)
1466+
abs_target = os.path.abspath(target)
1467+
1468+
prefix = os.path.commonprefix([abs_directory, abs_target])
1469+
1470+
return prefix == abs_directory
1471+
1472+
def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
1473+
1474+
for member in tar.getmembers():
1475+
member_path = os.path.join(path, member.name)
1476+
if not is_within_directory(path, member_path):
1477+
raise Exception("Attempted Path Traversal in Tar File")
1478+
1479+
tar.extractall(path, members, numeric_owner=numeric_owner)
1480+
1481+
1482+
safe_extract(f, os.path.dirname(matfiles_path))
14641483
os.remove(matfiles_path + ".tar.gz")
14651484
main()

0 commit comments

Comments
 (0)