From ebe19adc2383e9bb2898788beba5bcca0638cd3b Mon Sep 17 00:00:00 2001 From: geisserml Date: Sat, 7 Oct 2023 21:01:57 +0200 Subject: [PATCH] version checksum mismatch: warn rather than assert There's a chance checksum mismatch might simply be due to inconsistent serialization. Avoid breakage in that case. --- src/pypdfium2/version.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pypdfium2/version.py b/src/pypdfium2/version.py index 956ff5457..2d3b0b9b6 100644 --- a/src/pypdfium2/version.py +++ b/src/pypdfium2/version.py @@ -5,9 +5,12 @@ import json import hashlib +import logging from pathlib import Path import pypdfium2_raw +logger = logging.getLogger(__name__) + def _hash_data(data): return hashlib.md5(json.dumps(data).encode()).hexdigest() @@ -16,7 +19,9 @@ def _load_info(fp): with open(fp, "r") as buf: data = json.load(buf) checksum = data.pop("_checksum_") - assert _hash_data(data) == checksum, f"{'/'.join(fp.parts[-2:])} checksum mismatch - file corrupt or inconsistent serialization." + if not _hash_data(data) == checksum: + data["version"] += "!invalid" + logger.critical(f"Caution: {'/'.join(fp.parts[-2:])} checksum mismatch - file corrupt or inconsistent serialization. Please submit a bug report if you did not touch the data.") return data