Skip to content

Commit e2cec67

Browse files
author
Lukas Pühringer
authored
Merge pull request #2137 from n-dusan/ndusan/fix-incorrect-length-metapath-validation
Fix: allow `length` to be zero
2 parents 7e51f35 + 604eef2 commit e2cec67

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

tests/test_metadata_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def test_invalid_root_serialization(self, test_case_data: str) -> None:
297297
invalid_metafiles: utils.DataSet = {
298298
"wrong length type": '{"version": 1, "length": "a", "hashes": {"sha256" : "abc"}}',
299299
"version 0": '{"version": 0, "length": 1, "hashes": {"sha256" : "abc"}}',
300-
"length 0": '{"version": 1, "length": 0, "hashes": {"sha256" : "abc"}}',
301300
"length below 0": '{"version": 1, "length": -1, "hashes": {"sha256" : "abc"}}',
302301
"empty hashes dict": '{"version": 1, "length": 1, "hashes": {}}',
303302
"hashes wrong type": '{"version": 1, "length": 1, "hashes": 1}',
@@ -313,6 +312,7 @@ def test_invalid_metafile_serialization(self, test_case_data: str) -> None:
313312
valid_metafiles: utils.DataSet = {
314313
"all": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1}',
315314
"no length": '{"hashes": {"sha256" : "abc"}, "version": 1 }',
315+
"length 0": '{"version": 1, "length": 0, "hashes": {"sha256" : "abc"}}',
316316
"no hashes": '{"length": 12, "version": 1}',
317317
"unrecognized field": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1, "foo": "bar"}',
318318
"many hashes": '{"hashes": {"sha256" : "abc", "sha512": "cde"}, "length": 12, "version": 1}',

tuf/api/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,8 @@ def _validate_hashes(hashes: Dict[str, str]) -> None:
10521052

10531053
@staticmethod
10541054
def _validate_length(length: int) -> None:
1055-
if length <= 0:
1056-
raise ValueError(f"Length must be > 0, got {length}")
1055+
if length < 0:
1056+
raise ValueError(f"Length must be >= 0, got {length}")
10571057

10581058

10591059
class MetaFile(BaseFile):

0 commit comments

Comments
 (0)