std::string decodeBase64(
    const std::string& encoded) {

  if (encoded.size() == 0) {
    // special case, to prevent an integer overflow down below.
    return std::string();
  }

  int padding = 0;
  for (auto it = encoded.rbegin();
       padding < 2 && it != encoded.rend() && *it == '=';
       ++it) {
    ++padding;
  }

  return Base64::decode(encoded, padding);
}
The software writes data past the end, or before the beginning, of the intended buffer.