Skip to content

Commit a6d43a7

Browse files
committed
1 parent 369af47 commit a6d43a7

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

setupsrc/pypdfium2_setup/update_pdfium.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import traceback
1010
import functools
11+
import os.path
1112
from pathlib import Path
1213
from urllib import request
1314
from concurrent.futures import ThreadPoolExecutor
@@ -88,11 +89,8 @@ def safe_extract(tar, dest_dir, **kwargs):
8889

8990
dest_dir = dest_dir.resolve()
9091
for member in tar.getmembers():
91-
# if str(dest_dir) != os.path.commonprefix( [dest_dir, (dest_dir/member.name).resolve()] ):
92-
# ^ initial @Kasimir123/@TrellixVulnTeam logic, simplified into a one-liner; code below should have same effect
93-
# (yes, this also works against absolute paths)
9492
# if not (dest_dir/member.name).resolve().is_relative_to(dest_dir): # python >= 3.9
95-
if not str( (dest_dir/member.name).resolve() ).startswith( str(dest_dir) ):
93+
if str(dest_dir) != os.path.commonprefix( [dest_dir, (dest_dir/member.name).resolve()] ):
9694
raise RuntimeError("Attempted path traversal in tar archive (probably malicious).")
9795
tar.extractall(dest_dir, **kwargs)
9896

0 commit comments

Comments
 (0)