Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using tarfile.tar_filter to avoid malicious files #847

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading