Onionr/onionr/utils/safezip.py
2019-09-28 00:37:24 -05:00

8 lines
372 B
Python

# safe unzip https://stackoverflow.com/a/36583849
def safe_unzip(zip_file, extractpath='.'):
with zipfile.ZipFile(zip_file, 'r') as zf:
for member in zf.infolist():
abspath = os.path.abspath(os.path.join(extractpath, member.filename))
if abspath.startswith(os.path.abspath(extractpath)):
zf.extract(member, extractpath)