Handle errors when reading zip comments fixes #548

This commit is contained in:
Timmy Welch 2023-10-06 20:09:05 -07:00
parent 96c5c4aa28
commit edb087abde
2 changed files with 11 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import tempfile
import zipfile
from typing import cast
import chardet
from comicapi.archivers import Archiver
logger = logging.getLogger(__name__)
@ -23,7 +25,14 @@ class ZipArchiver(Archiver):
def get_comment(self) -> str:
with zipfile.ZipFile(self.path, "r") as zf:
comment = zf.comment.decode("utf-8")
encoding = chardet.detect(zf.comment, True)
if encoding["confidence"] > 60:
try:
comment = zf.comment.decode(encoding["encoding"])
except UnicodeDecodeError:
comment = zf.comment.decode("utf-8", errors="replace")
else:
comment = zf.comment.decode("utf-8", errors="replace")
return comment
def set_comment(self, comment: str) -> bool:

View File

@ -36,6 +36,7 @@ packages = find:
install_requires =
appdirs==1.4.4
beautifulsoup4>=4.1
chardet
importlib-metadata>=3.3.0
natsort>=8.1.0
pathvalidate