about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-17 10:01:47 -0400
committerJune McEnroe <june@causal.agency>2020-04-17 10:01:47 -0400
commitf3c1b53797618dc92760300dda2ed54d19de7589 (patch)
treeaf7174b5ac4c9ab0ecff668ae656d2410ad28db6
parentDecode base64 (diff)
downloadbubger-f3c1b53797618dc92760300dda2ed54d19de7589.tar.gz
bubger-f3c1b53797618dc92760300dda2ed54d19de7589.zip
Skip invalid characters in base64
Diffstat (limited to '')
-rw-r--r--decode.c11
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;