Fix ungraceful error on BadZipFile
This commit is contained in:
@@ -20,7 +20,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile, BadZipFile
|
||||||
|
|
||||||
import gitdb
|
import gitdb
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
@@ -306,13 +306,16 @@ def _check_zip_file(temp_dir: str, zf: ZipFile) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def _safe_extract_zip(temp_dir: str, archive_path: str) -> bool:
|
def _safe_extract_zip(temp_dir: str, archive_path: str) -> bool:
|
||||||
with ZipFile(archive_path, 'r') as zf:
|
try:
|
||||||
if not _check_zip_file(temp_dir, zf):
|
with ZipFile(archive_path, 'r') as zf:
|
||||||
return False
|
if not _check_zip_file(temp_dir, zf):
|
||||||
|
return False
|
||||||
|
|
||||||
# Extract all
|
# Extract all
|
||||||
for member in zf.infolist():
|
for member in zf.infolist():
|
||||||
zf.extract(member, temp_dir)
|
zf.extract(member, temp_dir)
|
||||||
|
except BadZipFile as e:
|
||||||
|
raise TaskError(str(e))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user