Skip to content

Commit

Permalink
Port of #3357: Fix/insecure tempfile (#3360)
Browse files Browse the repository at this point in the history
* Replaced insecure tempfile.mktemp() with tempfile.mkstemp()
Co-authored-by: whokilleddb <whokilleddb@gmail.com>
  • Loading branch information
dmitryduev committed Mar 10, 2022
1 parent 2e1d170 commit 7c1306c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wandb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def _filter_timestamps(tar_info: "tarfile.TarInfo") -> Optional["tarfile.TarInfo
tar_info.mtime = 0
return tar_info if custom_filter is None else custom_filter(tar_info)

unzipped_filename = tempfile.mktemp()
descriptor, unzipped_filename = tempfile.mkstemp()
try:
with tarfile.open(unzipped_filename, "w") as tar:
tar.add(source_dir, arcname=archive_name, filter=_filter_timestamps)
Expand All @@ -397,6 +397,7 @@ def _filter_timestamps(tar_info: "tarfile.TarInfo") -> Optional["tarfile.TarInfo
) as gzipped_tar, open(unzipped_filename, "rb") as tar_file:
gzipped_tar.write(tar_file.read())
finally:
os.close(descriptor)
os.remove(unzipped_filename)


Expand Down

0 comments on commit 7c1306c

Please sign in to comment.