mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +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 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user