Skip to content

Commit

Permalink
fix extract all (microsoft#726)
Browse files Browse the repository at this point in the history
* fix extract all
  • Loading branch information
rainLiuplus authored Dec 3, 2019
1 parent 6f2893e commit 414114b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mmdnn/conversion/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,27 @@ def download_file(url, directory='./', local_fname=None, force_write=False, auto
try:
import tarfile
tar = tarfile.open(ret)
for name in tar.getnames():
if not (os.path.realpath(os.path.join(directory, name))+ os.sep).startswith(os.path.realpath(directory) + os.sep):
raise ValueError('The decompression path does not match the current path. For more info: https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall')
tar.extractall(directory)
tar.close()
except ValueError:
raise
except:
print("Unzip file [{}] failed.".format(ret))

elif ret.endswith('.zip'):
try:
import zipfile
zip_ref = zipfile.ZipFile(ret, 'r')
for name in zip_ref.namelist():
if not (os.path.realpath(os.path.join(directory, name))+ os.sep).startswith(os.path.realpath(directory) + os.sep):
raise ValueError('The decompression path does not match the current path. For more info: https://docs.python.org/3/library/zipfile.html?highlight=zipfile#zipfile.ZipFile.extractall')
zip_ref.extractall(directory)
zip_ref.close()
except ValueError:
raise
except:
print("Unzip file [{}] failed.".format(ret))
return ret
Expand Down

0 comments on commit 414114b

Please sign in to comment.