Skip to content

Commit

Permalink
Early exit if base64 source is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Aug 4, 2023
1 parent 0d3b76f commit 67dc6ff
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sdk/src/common/base64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static int Base64UnescapeInternal(unsigned char *dst,
// 2045.
OPENTELEMETRY_EXPORT void Base64Escape(opentelemetry::nostd::string_view src, std::string *dest)
{
if (nullptr == dest)
if (nullptr == dest || src.empty())
{
return;
}
Expand Down Expand Up @@ -322,6 +322,11 @@ OPENTELEMETRY_EXPORT bool Base64Unescape(opentelemetry::nostd::string_view src,
#if defined(HAVE_ABSEIL)
return absl::Base64Unescape(absl::string_view{src.data(), src.size()}, dest);
#else
if (src.empty())
{
return true;
}

std::size_t olen = 0;

if (-2 == Base64UnescapeInternal(nullptr, 0, &olen,
Expand All @@ -331,11 +336,6 @@ OPENTELEMETRY_EXPORT bool Base64Unescape(opentelemetry::nostd::string_view src,
return false;
}

if (src.empty())
{
return true;
}

dest->resize(olen);
Base64UnescapeInternal(reinterpret_cast<unsigned char *>(&(*dest)[0]), dest->size(), &olen,
reinterpret_cast<const unsigned char *>(src.data()), src.size(),
Expand Down

0 comments on commit 67dc6ff

Please sign in to comment.