diff options
author | June McEnroe <june@causal.agency> | 2020-04-17 10:01:47 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-04-17 10:01:47 -0400 |
commit | f3c1b53797618dc92760300dda2ed54d19de7589 (patch) | |
tree | af7174b5ac4c9ab0ecff668ae656d2410ad28db6 | |
parent | Decode base64 (diff) | |
download | bubger-f3c1b53797618dc92760300dda2ed54d19de7589.tar.gz bubger-f3c1b53797618dc92760300dda2ed54d19de7589.zip |
Skip invalid characters in base64
Diffstat (limited to '')
-rw-r--r-- | decode.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/decode.c b/decode.c index a106c9c..24de9d3 100644 --- a/decode.c +++ b/decode.c @@ -86,16 +86,21 @@ static void convertCharset( iconv_close(conv); } +static const char Base64[64] = { + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +}; + static uint8_t unbase64(char ch) { - static const char Base64[64] = { - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" - }; const char *ptr = strchr(Base64, ch); return (ptr ? ptr - Base64 : 0); } static void decodeBase64(struct Buffer *dst, const char *src) { while (src[0] && src[1] && src[2] && src[3]) { + if (!strchr(Base64, src[0])) { + src++; + continue; + } uint32_t bits = 0; for (int i = 0; i < 4; ++i) { bits <<= 6; |