diff --git a/velox/common/encode/Base64.cpp b/velox/common/encode/Base64.cpp index e866e6ea99d9f..fe03bcc720cbb 100644 --- a/velox/common/encode/Base64.cpp +++ b/velox/common/encode/Base64.cpp @@ -156,7 +156,7 @@ static_assert( // "kBase64UrlReverseIndexTable has incorrect entries."); // Implementation of Base64 encoding and decoding functions. -// static +// static template std::string Base64::encodeImpl( const T& data, @@ -194,7 +194,7 @@ Status Base64::encodeUrl(std::string_view data, char* output) { return encodeImpl(data, kBase64UrlCharset, true, output); } -// static +// static template Status Base64::encodeImpl( const T& data, @@ -339,7 +339,7 @@ uint8_t Base64::base64ReverseLookup( } // static -size_t Base64::decode( +Status Base64::decode( std::string_view src, size_t src_len, char* dst, @@ -391,19 +391,19 @@ size_t Base64::calculateDecodedSize(std::string_view data, size_t& size) { } // static -size_t Base64::decodeImpl( +Status Base64::decodeImpl( std::string_view src, size_t src_len, char* dst, size_t dst_len, const Base64::ReverseIndex& reverseIndex) { if (!src_len) { - return 0; + return Status::OK(); } auto needed = calculateDecodedSize(src, src_len); if (dst_len < needed) { - VELOX_USER_FAIL( + return Status::UserError( "Base64::decode() - invalid output string: " "output string is too small."); } @@ -437,7 +437,7 @@ size_t Base64::decodeImpl( } } - return needed; + return Status::OK(); } // static @@ -451,12 +451,12 @@ std::string Base64::encodeUrl(const folly::IOBuf* data) { } // static -void Base64::decodeUrl( +Status Base64::decodeUrl( std::string_view src, size_t src_len, char* dst, size_t dst_len) { - decodeImpl(src, src_len, dst, dst_len, kBase64UrlReverseIndexTable); + return decodeImpl(src, src_len, dst, dst_len, kBase64UrlReverseIndexTable); } // static @@ -470,7 +470,7 @@ std::string Base64::decodeUrl(std::string_view encoded) { void Base64::decodeUrl(std::string_view payload, std::string& output) { size_t out_len = (payload.size() + 3) / 4 * 3; output.resize(out_len, '\0'); - out_len = Base64::decodeImpl( + Base64::decodeImpl( payload.data(), payload.size(), &output[0], diff --git a/velox/common/encode/Base64.h b/velox/common/encode/Base64.h index aeac7275a3686..cb03218c8899f 100644 --- a/velox/common/encode/Base64.h +++ b/velox/common/encode/Base64.h @@ -93,12 +93,12 @@ class Base64 { /// Decodes the specified number of characters from the 'src' and writes the /// result to the 'dst'. - static size_t + static Status decode(std::string_view src, size_t src_len, char* dst, size_t dst_len); /// Decodes the specified number of characters from the 'src' using URL /// encoding and writes the result to the 'dst'. - static void + static Status decodeUrl(std::string_view src, size_t src_len, char* dst, size_t dst_len); private: @@ -138,7 +138,7 @@ class Base64 { char* out); // Decodes the specified data using the provided reverse lookup table. - static size_t decodeImpl( + static Status decodeImpl( std::string_view src, size_t src_len, char* dst, diff --git a/velox/functions/prestosql/BinaryFunctions.h b/velox/functions/prestosql/BinaryFunctions.h index a6d1096ee4585..c3afa379450d6 100644 --- a/velox/functions/prestosql/BinaryFunctions.h +++ b/velox/functions/prestosql/BinaryFunctions.h @@ -290,11 +290,11 @@ struct FromBase64Function { // T can be either arg_type or arg_type. These are the // same, but hard-coding one of them might be confusing. template - FOLLY_ALWAYS_INLINE void call(out_type& result, const T& input) { + FOLLY_ALWAYS_INLINE Status call(out_type& result, const T& input) { auto inputSize = input.size(); result.resize( encoding::Base64::calculateDecodedSize(input.data(), inputSize)); - encoding::Base64::decode( + return encoding::Base64::decode( input.data(), inputSize, result.data(), result.size()); } }; @@ -302,13 +302,12 @@ struct FromBase64Function { template struct FromBase64UrlFunction { VELOX_DEFINE_FUNCTION_TYPES(T); - FOLLY_ALWAYS_INLINE void call( - out_type& result, - const arg_type& input) { + FOLLY_ALWAYS_INLINE Status + call(out_type& result, const arg_type& input) { auto inputSize = input.size(); result.resize( encoding::Base64::calculateDecodedSize(input.data(), inputSize)); - encoding::Base64::decodeUrl( + return encoding::Base64::decodeUrl( input.data(), inputSize, result.data(), result.size()); } };