Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_base64 past-of-end iterator increment for invalid base64 string #324

Open
ROCKFAL1 opened this issue Jan 28, 2025 · 0 comments
Open

Comments

@ROCKFAL1
Copy link

ROCKFAL1 commented Jan 28, 2025

Compiler: MSVC
boost version: 1.86.0

For any string with size() % 4 == 1 from_base64 function increments past-of-end iterator
Is this behavior expected? If this behavior is expected, then why doesn't the library provide functions for base64 validation?

MRE:

#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>

template <typename OutIt>
OutIt from_base64(const char* pstr, size_t size, OutIt out)
{
  using namespace boost::archive::iterators;

  std::vector<char> buffer; // Just for debugging 
  std::copy_n(pstr, size, std::back_inserter(buffer));

  using It = transform_width<binary_from_base64<std::vector<char>::iterator>, 8, 6>;
  return  std::copy(It(buffer.begin()), It(buffer.end()), out);
}

const std::string base64str= "MTIzN"; // base64("1234567890") == "MTIzNDU2Nzg5MA=="
std::string result;
from_base64(base64str.c_str(), base64str.size(), std::back_inserter(result));
 // Here i'm expecting smth like `result == "123"`, or `from_base64` throw exception (that i can wrap and return only valid part - "123")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant