fix(utils): catch MemoryError in read_safetensors_metadata for non-safetensors files

This commit is contained in:
Will Miao
2026-06-05 16:30:50 +08:00
parent 01dac57c35
commit d9ee9b3155

View File

@@ -81,7 +81,7 @@ def read_safetensors_metadata(file_path: str) -> dict[str, Any]:
return {}
header = json.loads(header_bytes.decode("utf-8"))
return header.get("__metadata__", {})
except (OSError, json.JSONDecodeError, UnicodeDecodeError, struct.error):
except (OSError, json.JSONDecodeError, UnicodeDecodeError, struct.error, MemoryError, Exception):
return {}