mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-09 17:13:45 +01:00
Fix ungraceful error on BadZipFile
This commit is contained in:
parent
ed4d4c67d9
commit
e5e3230a16
@ -20,7 +20,7 @@ import os
|
||||
import shutil
|
||||
import sys
|
||||
from json import JSONDecodeError
|
||||
from zipfile import ZipFile
|
||||
from zipfile import ZipFile, BadZipFile
|
||||
|
||||
import gitdb
|
||||
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:
|
||||
with ZipFile(archive_path, 'r') as zf:
|
||||
if not _check_zip_file(temp_dir, zf):
|
||||
return False
|
||||
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)
|
||||
# Extract all
|
||||
for member in zf.infolist():
|
||||
zf.extract(member, temp_dir)
|
||||
except BadZipFile as e:
|
||||
raise TaskError(str(e))
|
||||
|
||||
return True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user