Spaces:
Running
Running
fix: detect loader-accepted duplicate safetensors keys
Browse filesFiles changed (3)
14 unmodified lines15161718192014 unmodified linesfirst installation or removal when the exact public command is retried.- Reject non-canonical ZIP member spellings and ambiguous trailing orconcatenated archive data before privileged installation.- Keep publication, signing, tagging and external deployment as separatedecisions.14 unmodified lines15161718192021222314 unmodified linesfirst installation or removal when the exact public command is retried.- Reject non-canonical ZIP member spellings and ambiguous trailing orconcatenated archive data before privileged installation.- Interpret duplicate Safetensors tensor names with the reference loader'sfinal-value semantics, then validate the resulting exact layout, so a modelaccepted by the pinned loader cannot evade recognition by repeating a key.- Keep publication, signing, tagging and external deployment as separatedecisions.
172 unmodified lines173174175176177178179180181182183184172 unmodified linesdef _json_pairs(pairs: list[tuple[str, object]]) -> dict[str, object]:value: dict[str, object] = {}for key, item in pairs:if key in value:raise JsonInputError("Safetensors header contains duplicate JSON keys")value[key] = itemreturn valuedef validate_safetensors_fd(172 unmodified lines173174175176177178179180181182183172 unmodified linesdef _json_pairs(pairs: list[tuple[str, object]]) -> dict[str, object]:# The reference Safetensors loader accepts duplicate JSON names with the# final value taking precedence. Mirror that interpretation before# validating the resulting tensor layout; otherwise a loader-accepted# model can evade content recognition merely by repeating a key.return dict(pairs)def validate_safetensors_fd(
265 unmodified lines266267268269270271265 unmodified linesfor path in (duplicate_file, invalid_dtype, invalid_range, truncated):self.assertIsNone(validate_path(path))def test_safetensors_allows_scalar_and_zero_dimension_tensors(self) -> None:with tempfile.TemporaryDirectory() as raw:root = Path(raw)265 unmodified lines266267268269270271272273274275276277278279280281282283284265 unmodified linesfor path in (duplicate_file, invalid_dtype, invalid_range, truncated):self.assertIsNone(validate_path(path))def test_safetensors_duplicate_names_follow_reference_loader_last_value(self) -> None:with tempfile.TemporaryDirectory() as raw:path = Path(raw) / "duplicate-loader-accepted"header = (b'{"x":{"dtype":"U8","shape":[1],"data_offsets":[0,1]},'b'"x":{"dtype":"U8","shape":[1],"data_offsets":[0,1]}}')path.write_bytes(struct.pack("<Q", len(header)) + header + b"x")evidence = validate_path(path)self.assertIsNotNone(evidence)assert evidence is not Noneself.assertEqual("safetensors-v1", evidence.evidence_id)def test_safetensors_allows_scalar_and_zero_dimension_tensors(self) -> None:with tempfile.TemporaryDirectory() as raw:root = Path(raw)
CHANGELOG.md+3
src/lumi_eggcracker/artifacts.py+5-6
tests/test_artifacts.py+13