From bce1b0b19d29140f212fcc75904473a164cf68a9 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 13 Nov 2023 08:34:28 -0600 Subject: [PATCH] GH-1461 Do not require trailing `=` for base64 encoded strings to support non-fc valid base64 encodings --- libraries/libfc/src/variant.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/libfc/src/variant.cpp b/libraries/libfc/src/variant.cpp index 4b81c3c06c..41946ae2ac 100644 --- a/libraries/libfc/src/variant.cpp +++ b/libraries/libfc/src/variant.cpp @@ -525,10 +525,14 @@ blob variant::as_blob()const { const string& str = get_string(); if( str.size() == 0 ) return blob(); - if( str.back() == '=' ) - { - std::string b64 = base64_decode( get_string() ); + try { + // variant adds `=` to end of base64 encoded string (see as_string() above) which produces invalid base64 + // variant in 5.0 no longer appends the '=' character to conform to valid base64 encoding + // fc version of base64_decode allows for extra `=` at the end of the string + std::string b64 = base64_decode( str ); return blob( { std::vector( b64.begin(), b64.end() ) } ); + } catch(const std::exception&) { + // unable to decode, return raw chars } return blob( { std::vector( str.begin(), str.end() ) } ); }