Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strkey: Check for leftover character to be in the expected alphabet #3529

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions strkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ func decodeString(src string) ([]byte, error) {
if leftoverBits > 0 {
lastChar := srcBytes[len(srcBytes)-1]
decodedLastChar := decodingTable[lastChar]
if decodedLastChar == 0xff {
// The last character from the input wasn't in the expected input alphabet.
// Let's output an error matching the errors from the base32 decoder invocation below
return nil, errors.Wrap(base32.CorruptInputError(len(srcBytes)), "base32 decode failed")
}
2opremio marked this conversation as resolved.
Show resolved Hide resolved
leftoverBitsMask := byte(0x0f) >> (4 - leftoverBits)
if decodedLastChar&leftoverBitsMask != 0 {
return nil, errors.New("non-canonical strkey; unused bits should be set to 0")
Expand Down