Skip to content

Commit

Permalink
Using tarfile.tar_filter to avoid malicious files
Browse files Browse the repository at this point in the history
  • Loading branch information
tfmoraes committed Sep 23, 2024
1 parent bac2e2a commit f135478
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions invesalius/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,9 @@ def Extract(filename: Union[str, bytes, os.PathLike], folder: Union[str, bytes,
os.mkdir(os.path.join(folder, idir))
filelist = []
for t in tar.getmembers():
fsrc = tar.extractfile(t)
if fsrc is None:
raise Exception("Error extracting file")
tar.extract(t, path=folder, filter=tarfile.tar_filter)
fname = os.path.join(folder, decode(t.name, "utf-8"))
fdst = open(fname, "wb")
shutil.copyfileobj(fsrc, fdst)
filelist.append(fname)
fsrc.close()
fdst.close()
del fsrc
del fdst
tar.close()
return filelist

Expand Down

0 comments on commit f135478

Please sign in to comment.