Merge pull request #2137 from n-dusan/ndusan/fix-incorrect-length-metapath-validation

Fix: allow `length` to be zero
This commit is contained in:
Lukas Pühringer 2022-10-17 09:49:44 +02:00 committed by GitHub
commit e2cec677ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -297,7 +297,6 @@ def test_invalid_root_serialization(self, test_case_data: str) -> None:
invalid_metafiles: utils.DataSet = {
"wrong length type": '{"version": 1, "length": "a", "hashes": {"sha256" : "abc"}}',
"version 0": '{"version": 0, "length": 1, "hashes": {"sha256" : "abc"}}',
"length 0": '{"version": 1, "length": 0, "hashes": {"sha256" : "abc"}}',
"length below 0": '{"version": 1, "length": -1, "hashes": {"sha256" : "abc"}}',
"empty hashes dict": '{"version": 1, "length": 1, "hashes": {}}',
"hashes wrong type": '{"version": 1, "length": 1, "hashes": 1}',
@ -313,6 +312,7 @@ def test_invalid_metafile_serialization(self, test_case_data: str) -> None:
valid_metafiles: utils.DataSet = {
"all": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1}',
"no length": '{"hashes": {"sha256" : "abc"}, "version": 1 }',
"length 0": '{"version": 1, "length": 0, "hashes": {"sha256" : "abc"}}',
"no hashes": '{"length": 12, "version": 1}',
"unrecognized field": '{"hashes": {"sha256" : "abc"}, "length": 12, "version": 1, "foo": "bar"}',
"many hashes": '{"hashes": {"sha256" : "abc", "sha512": "cde"}, "length": 12, "version": 1}',

View file

@ -1052,8 +1052,8 @@ def _validate_hashes(hashes: Dict[str, str]) -> None:
@staticmethod
def _validate_length(length: int) -> None:
if length <= 0:
raise ValueError(f"Length must be > 0, got {length}")
if length < 0:
raise ValueError(f"Length must be >= 0, got {length}")
class MetaFile(BaseFile):