Repository navigation
Conversation
Signed-off-by: Yan Chen <yan8925298@gmail.com>
EmiRZx
reviewed
Dec 2, 2026
EmiRZx
left a comment
There was a problem hiding this comment.
tested locally, tests pass and true/false are now rejected. floats still get through though. 1.5 is accepted for version, threshold and length and written back as 1.5, while the new messages say these must be integers. type(x) is not int would cover bool and float in one check.
Signed-off-by: Yan Chen <yan8925298@gmail.com>
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Python,
boolis a subclass ofint(isinstance(True, int) == True, withFalse == 0andTrue == 1). As a result, TUF metadata integer validations intuf/api/_payload.pyaccepted JSON boolean values (true/false) for integer fields required by the TUF specification:Signed.version("version": trueaccepted as1, passingversion <= 0)Role.threshold("threshold": trueaccepted as1, passingthreshold < 1)BaseFile._validate_lengthused byMetaFile.lengthandTargetFile.length("length": falseaccepted as0and"length": trueaccepted as1, even passingverify_length_and_hashes(b"")/verify_length_and_hashes(b"a"))MetaFile.version("version": trueaccepted as1)SuccinctRoles.bit_length("bit_length": trueaccepted as1)And when re-serialized via
to_dict()/to_bytes(), those fields were emitted as JSON booleans (true/false) instead of integers.Changes
tuf/api/_payload.py: Explicitly rejectbool(isinstance(..., bool)) withValueErrorinSigned.__init__,Role.__init__,BaseFile._validate_length,MetaFile.__init__, andSuccinctRoles.__init__.tests/test_metadata_serialization.py&tests/test_api.py: Add regression test cases verifying booleanversion,threshold,length, andbit_lengthvalues are rejected cleanly (and raiseDeserializationErrorduring metadata/DSSE deserialization).Verification
Metadata.from_bytes,MetaFile.from_dict,TargetFile.from_dict,Role.from_dict, andSuccinctRoles.from_dictall accepted boolean values before the fix and reject them cleanly after.pytest tests -q: 208 passed, 207 subtests passed.