Skip to content

Commit

Permalink
base64Decode: clearer error message when an invalid character is dete…
Browse files Browse the repository at this point in the history
…cted

Output the offending string in its entirety to provide context.

Closes NixOS#8479
  • Loading branch information
brianmcgee committed Jul 31, 2023
1 parent dcdd5fe commit dc217c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1618,8 +1618,9 @@ std::string base64Decode(std::string_view s)
if (c == '\n') continue;

char digit = base64DecodeChars[(unsigned char) c];
if (digit == npos)
throw Error("invalid character in Base64 string: '%c'", c);
if (digit == npos) {
throw Error("invalid character in Base64 string: '%c' in %s", c, s.data());
}

bits += 6;
d = d << 6 | digit;
Expand Down

0 comments on commit dc217c8

Please sign in to comment.