Skip to content

Commit

Permalink
Fix ungraceful error on BadZipFile
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Aug 5, 2024
1 parent ed4d4c6 commit e5e3230
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/tasks/importtasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import shutil
import sys
from json import JSONDecodeError
from zipfile import ZipFile
from zipfile import ZipFile, BadZipFile

import gitdb
from flask import url_for
Expand Down Expand Up @@ -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:
with ZipFile(archive_path, 'r') as zf:
if not _check_zip_file(temp_dir, zf):
return False

# Extract all
for member in zf.infolist():
zf.extract(member, temp_dir)
try:
with ZipFile(archive_path, 'r') as zf:
if not _check_zip_file(temp_dir, zf):
return False

# Extract all
for member in zf.infolist():
zf.extract(member, temp_dir)
except BadZipFile as e:
raise TaskError(str(e))

return True

Expand Down

0 comments on commit e5e3230

Please sign in to comment.