@@ -719,6 +719,13 @@ def from_dict(cls, meta_dict: Dict[str, Any]) -> "MetaFile":
719
719
version = meta_dict .pop ("version" )
720
720
length = meta_dict .pop ("length" , None )
721
721
hashes = meta_dict .pop ("hashes" , None )
722
+
723
+ # Do some basic input validation
724
+ if version <= 0 :
725
+ raise ValueError (f"Metafile version must be > 0, got { version } " )
726
+ if length is not None and length <= 0 :
727
+ raise ValueError (f"Metafile length must be > 0, got { length } " )
728
+
722
729
# All fields left in the meta_dict are unrecognized.
723
730
return cls (version , length , hashes , meta_dict )
724
731
@@ -1019,6 +1026,13 @@ def from_dict(cls, target_dict: Dict[str, Any]) -> "TargetFile":
1019
1026
"""Creates TargetFile object from its dict representation."""
1020
1027
length = target_dict .pop ("length" )
1021
1028
hashes = target_dict .pop ("hashes" )
1029
+
1030
+ # Do some basic validation checks
1031
+ if length <= 0 :
1032
+ raise ValueError (f"Targetfile length must be > 0, got { length } " )
1033
+ if not hashes :
1034
+ raise ValueError ("Missing targetfile hashes" )
1035
+
1022
1036
# All fields left in the target_dict are unrecognized.
1023
1037
return cls (length , hashes , target_dict )
1024
1038
0 commit comments