Skip to content

Verifying a sharded signature without a hashing config fails: shard_size is read back as a float #690

Open

Description

@VISHNU0906

Verifying a shard-serialized signature without an explicit hashing config fails with a TypeError instead of verifying.

The signing payload goes through a protobuf Struct, so shard_size is written as a double ("shard_size": 4.0 in the DSSE payload). When verifying.Config has no hashing config, _guess_hashing_config passes that float to use_shard_serialization, and _endpoints then calls range() with it.

Reproducer on main (05e665f), using the test keys in scripts/tests/keys/certificate:

import pathlib, tempfile
from model_signing import hashing, signing, verifying

keys = pathlib.Path("scripts/tests/keys/certificate")
tmp = pathlib.Path(tempfile.mkdtemp())
model = tmp / "model"
model.mkdir()
(model / "weights").write_bytes(b"x" * 100)
sig = tmp / "model.sig"

signing.Config().use_elliptic_key_signer(
    private_key=keys / "signing-key.pem"
).set_hashing_config(
    hashing.Config().use_shard_serialization(shard_size=40)
).sign(model, sig)

verifying.Config().use_elliptic_key_verifier(
    public_key=keys / "signing-key-pub.pem"
).verify(model, sig)
  File ".../model_signing/_serialization/file_shard.py", line 50, in _endpoints
    yield from range(step, end, step)
TypeError: 'float' object cannot be interpreted as an integer

The existing sharded tests all pass an explicit set_hashing_config(...use_shard_serialization()) to the verifier, so the guessed path is not covered.

The spec defines shard_size as a positive integer, and existing signatures already carry the .0 form, so I think the fix belongs on the reading side: accept a whole-number float when the manifest is rebuilt from the signature (_ShardSerialization._from_args) and reject anything that is not a positive whole number. I have a small patch with tests and will open a PR linking this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions