diff --git a/AK/Base64.cpp b/AK/Base64.cpp index 112c02e603c..058fd808a69 100644 --- a/AK/Base64.cpp +++ b/AK/Base64.cpp @@ -15,7 +15,14 @@ namespace AK { size_t calculate_base64_decoded_length(StringView input) { - return input.length() * 3 / 4; + auto length = input.length() * 3 / 4; + + if (input.ends_with("="sv)) + --length; + if (input.ends_with("=="sv)) + --length; + + return length; } size_t calculate_base64_encoded_length(ReadonlyBytes input) @@ -70,9 +77,6 @@ static ErrorOr decode_base64_impl(StringView input, ReadonlySpan