Sanitize ownership when extracting tarfiles (#31524)
This commit is contained in:
parent
5bd1074afb
commit
25f198aa91
@ -79,9 +79,15 @@ def _untar(archive_file):
|
|||||||
if tar_support() and not uncompress_required and\
|
if tar_support() and not uncompress_required and\
|
||||||
not lzma_needed_and_not_available:
|
not lzma_needed_and_not_available:
|
||||||
import tarfile
|
import tarfile
|
||||||
tar = tarfile.open(archive_file)
|
|
||||||
tar.extractall()
|
# Extract all members but wipe ownership info. This ensures we
|
||||||
tar.close()
|
# will not attempt to chown the files as superuser.
|
||||||
|
def filter(tarinfo):
|
||||||
|
tarinfo.uid = tarinfo.gid = 0
|
||||||
|
tarinfo.uname = tarinfo.gname = 'root'
|
||||||
|
return tarinfo
|
||||||
|
with tarfile.open(archive_file) as tar:
|
||||||
|
tar.extractall(members=map(filter, tar.getmembers()))
|
||||||
else:
|
else:
|
||||||
tar = which('tar', required=True)
|
tar = which('tar', required=True)
|
||||||
tar.add_default_arg('-oxf')
|
tar.add_default_arg('-oxf')
|
||||||
|
Loading…
Reference in New Issue
Block a user