File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,12 @@ impl FromStr for Hash {
151
151
// hex
152
152
data_encoding:: HEXLOWER . decode_mut ( s. as_bytes ( ) , & mut bytes)
153
153
} else {
154
- data_encoding:: BASE32_NOPAD . decode_mut ( s. to_ascii_uppercase ( ) . as_bytes ( ) , & mut bytes)
154
+ let input = s. to_ascii_uppercase ( ) ;
155
+ let input = input. as_bytes ( ) ;
156
+ if data_encoding:: BASE32_NOPAD . decode_len ( input. len ( ) ) ? != bytes. len ( ) {
157
+ return Err ( HexOrBase32ParseError :: DecodeInvalidLength ) ;
158
+ }
159
+ data_encoding:: BASE32_NOPAD . decode_mut ( input, & mut bytes)
155
160
} ;
156
161
match res {
157
162
Ok ( len) => {
@@ -583,4 +588,9 @@ mod tests {
583
588
let de = serde_json:: from_str ( & ser) . unwrap ( ) ;
584
589
assert_eq ! ( haf, de) ;
585
590
}
591
+
592
+ #[ test]
593
+ fn test_hash_invalid ( ) {
594
+ let _ = Hash :: from_str ( "invalid" ) . unwrap_err ( ) ;
595
+ }
586
596
}
You can’t perform that action at this time.
0 commit comments