Skip to content

Commit

Permalink
[cleaner] Use data 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 sos extracts just tarballs that should be compliant with safe
extraction (no extracted file outside the target directory etc.), we
should stick to the data filter.

Relevant: sosreport#3319
Closes: sosreport#3330

Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
pmoravec committed Aug 8, 2023
1 parent 46794f4 commit 4e42e5f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sos/cleaner/archives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
def extract_archive(archive_path, tmpdir):
archive = tarfile.open(archive_path)
path = os.path.join(tmpdir, 'cleaner')
# set extract data filter since python 3.12 (see PEP-706 for more)
archive.extraction_filter = getattr(tarfile, 'data_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 4e42e5f

Please sign in to comment.