Onionr/src/utils/safezip.py
2019-11-21 02:23:58 -06: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)