Skip to content

Commit

Permalink
[cleaner] Use fully_trusted filter for extraction
Browse files Browse the repository at this point in the history
Since Python 3.12, archive.extractall would require setting an
extraction filter otherwise an exception is raised. See PEP 706 for
more.

Since Python 3.10 and 3.11 can raise false alarms as exceptions (see #3330
for examples), we must use the legacy fully_trusted filter.

Relevant: #3319
Closes: #3330

Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
pmoravec committed Aug 10, 2023
1 parent 46794f4 commit 8db4861
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sos/cleaner/archives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
def extract_archive(archive_path, tmpdir):
archive = tarfile.open(archive_path)
path = os.path.join(tmpdir, 'cleaner')
# set extract filter since python 3.12 (see PEP-706 for more)
# Because python 3.10 and 3.11 raises false alarms as exceptions
# (see #3330 for examples), we can't use data filter but must
# fully trust the archive (legacy behaviour)
archive.extraction_filter = getattr(tarfile, 'fully_trusted_filter',
(lambda member, path: member))
archive.extractall(path)
archive.close()
return os.path.join(path, archive.name.split('/')[-1].split('.tar')[0])
Expand Down

0 comments on commit 8db4861

Please sign in to comment.