Fix ungraceful error on BadZipFile

This commit is contained in:
rubenwardy 2024-08-05 12:11:44 +01:00
parent ed4d4c67d9
commit e5e3230a16

@ -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,6 +306,7 @@ 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:
try:
with ZipFile(archive_path, 'r') as zf: with ZipFile(archive_path, 'r') as zf:
if not _check_zip_file(temp_dir, zf): if not _check_zip_file(temp_dir, zf):
return False return False
@ -313,6 +314,8 @@ def _safe_extract_zip(temp_dir: str, archive_path: str) -> bool:
# 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