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 {
151151 // hex
152152 data_encoding:: HEXLOWER . decode_mut ( s. as_bytes ( ) , & mut bytes)
153153 } 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)
155160 } ;
156161 match res {
157162 Ok ( len) => {
@@ -583,4 +588,9 @@ mod tests {
583588 let de = serde_json:: from_str ( & ser) . unwrap ( ) ;
584589 assert_eq ! ( haf, de) ;
585590 }
591+
592+ #[ test]
593+ fn test_hash_invalid ( ) {
594+ let _ = Hash :: from_str ( "invalid" ) . unwrap_err ( ) ;
595+ }
586596}
You can’t perform that action at this time.
0 commit comments