Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions absl/strings/escaping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -954,17 +954,14 @@ bool WebSafeBase64Unescape(absl::string_view src,
return Base64UnescapeInternal(src.data(), src.size(), dest, kUnWebSafeBase64);
}


void Base64Escape(absl::string_view src, std::string* absl_nonnull dest) {
strings_internal::Base64EscapeInternal(
reinterpret_cast<const unsigned char*>(src.data()), src.size(), dest,
true, strings_internal::kBase64Chars);
*dest = Base64Escape(src);
}

void WebSafeBase64Escape(absl::string_view src,
std::string* absl_nonnull dest) {
strings_internal::Base64EscapeInternal(
reinterpret_cast<const unsigned char*>(src.data()), src.size(), dest,
false, strings_internal::kWebSafeBase64Chars);
*dest = WebSafeBase64Escape(src);
}

std::string Base64Escape(absl::string_view src) {
Expand Down
8 changes: 8 additions & 0 deletions absl/strings/escaping_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,12 @@ TEST(HexAndBack, HexStringToBytes_and_BytesToHexString) {
EXPECT_EQ(hex_only_lower, hex_result);
}

TEST(Base64Escape, AliasingSafety){
std::string s = "Abseil";
absl::Base64Escape(s, &s);
// would corrupt or crash before fix
// after fix: s should be "QWJzZWls"
EXPECT_EQ(s, "QWJzZWls");
}

} // namespace