Skip to content

Commit

Permalink
version checksum mismatch: warn rather than assert
Browse files Browse the repository at this point in the history
There's a chance checksum mismatch might simply be due to inconsistent
serialization. Avoid breakage in that case.
  • Loading branch information
mara004 committed Oct 7, 2023
1 parent 34397f5 commit ebe19ad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pypdfium2/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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


Expand Down

0 comments on commit ebe19ad

Please sign in to comment.