From f3c1b53797618dc92760300dda2ed54d19de7589 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 17 Apr 2020 10:01:47 -0400 Subject: Skip invalid characters in base64 --- decode.c | 11 ++++++++--- 1 file 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; -- cgit 1.4.1