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 <pmoravec@redhat.com>
  • Loading branch information
pmoravec authored and TurboTurtle committed Aug 15, 2023
1 parent 3ed37ad commit d71e6b5
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 d71e6b5

Please sign in to comment.