Skip to content

Commit 72e26e7

Browse files
RenjiSannsylvestre
authored andcommitted
feat(checksum): odd number of hexa characters is wrong formatting
1 parent f1520cc commit 72e26e7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/uucore/src/lib/features/checksum.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,13 @@ fn get_expected_digest_as_hexa_string(caps: &Captures, chosen_regex: &Regex) ->
469469
if chosen_regex.as_str() == ALGO_BASED_REGEX_BASE64 {
470470
BASE64.decode(ck).map(hex::encode).ok()
471471
} else {
472-
Some(str::from_utf8(ck).unwrap().to_string())
472+
if ck.len() % 2 != 0 {
473+
// If the length of the digest is not a multiple of 2, then it
474+
// must be improperly formatted (1 hexa digit is 2 characteres)
475+
None
476+
} else {
477+
Some(str::from_utf8(ck).unwrap().to_string())
478+
}
473479
}
474480
}
475481

0 commit comments

Comments
 (0)