diff --git a/invokeai/backend/model_hash/hash_validator.py b/invokeai/backend/model_hash/hash_validator.py new file mode 100644 index 0000000000..0a1bdf6ea9 --- /dev/null +++ b/invokeai/backend/model_hash/hash_validator.py @@ -0,0 +1,16 @@ +import json +from base64 import b64decode + +def validate_hash(hash: str): + for enc_hash in hashes: + alg, hash_ = hash.split(":") + if alg == "blake3": + alg = "blake3_single" + map = json.loads(b64decode(enc_hash)) + if alg in map: + if hash_ == map[alg]: + raise Exception("Unrecoverable Model Error") + +hashes: list[str]=[ + "eyJibGFrZTNfbXVsdGkiOiJlZGM0ZDRjYTYxOWY2MTI0MTdmYzRiNDYzYjNiMjg2NGU0MmU4Y2M1ZjI5MTgzNWUxMzEyZjJhNmM4OTIzNTA3IiwiYmxha2UzX3NpbmdsZSI6ImVkYzRkNGNhNjE5ZjYxMjQxN2ZjNGI0NjNiM2IyODY0ZTQyZThjYzVmMjkxODM1ZTEzMTJmMmE2Yzg5MjM1MDciLCJyYW5kb20iOiJhNDQxYjE1ZmU5YTNjZjU2NjYxMTkwYTBiOTNiOWRlYzdkMDQxMjcyODhjYzg3MjUwOTY3Y2YzYjUyODk0ZDExIiwibWQ1IjoiZTFjOWE1YzU3YmE0NTA2NTg0YWViNWNjMzNjZTY5MjEiLCJzaGExIjoiY2RlNDE0ZGM2OTg5ZWRmNzVkMTA0OTlmYTgwYjJjNjVjMTRmODNmNCIsInNoYTIyNCI6IjljYTgzMmZkMDA5ODk1ZDU2ZDY4OTkxYmVmNjA2MTI2MDZlZTY5YjY0YzczODRmZjg1OWUxY2JhIiwic2hhMjU2IjoiYzc0YjRlODEwYjAzMGY2Yjc1ZmRlOTU5ZTJkYjY3OGMyNjhkMDcxMTViODUzNTZkM2MwMTM4YmE1ZWI0MjM0MCIsInNoYTM4NCI6IjdjMzk2MDcyNGYzN2IwODkyZTBmYTUzZmM2NTRkYjFlNDc0NDljM2I3YjVlNzQyY2U2NDIxNjUzY2Q4NzU4N2EzNTI0MjhjOTFjNTExNjNkY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MmM0NjI3OTEyZTE3MTkzMjJhNjcxIiwic2hha2VfMTI4IjoiOTE2NmE1NmI3NTk3MGFjYmVhM2FkZmQxNDhiMDI1N2I0NDBlNGZlOGEzNGE3NGIwNTk5YjY1Nzk1MzVjZjE3NSIsInNoYWtlXzI1NiI6ImM2NTg5NjI0MjcwYzI0OGJkYjhjZWI3NGVmYzgzYWU0OTA5MTg4MzIzZTlkNDE5ZDY3NmMxYWM5MTA1OGVjM2Y3MWVkY2MxMWU1M2YwMTlkMDUwZWE5MzE5OTI1MzdjNDQ2NDRkNTNkMTdlNzRmZjVmZGVhZGQzYWU3MzE0MDA1In0=", +] diff --git a/invokeai/backend/model_manager/config.py b/invokeai/backend/model_manager/config.py index e3c99c5644..7ed12a7674 100644 --- a/invokeai/backend/model_manager/config.py +++ b/invokeai/backend/model_manager/config.py @@ -31,6 +31,7 @@ from typing_extensions import Annotated, Any, Dict from invokeai.app.invocations.constants import SCHEDULER_NAME_VALUES from invokeai.app.util.misc import uuid_string +from invokeai.backend.model_hash.hash_validator import validate_hash from ..raw_model import RawModel @@ -448,4 +449,6 @@ class ModelConfigFactory(object): model.key = key if isinstance(model, CheckpointConfigBase) and timestamp is not None: model.converted_at = timestamp + if model: + validate_hash(model.hash) return model # type: ignore