Base64 encoding broken for large payloads

There seem to be issues with Base64 encoding if the payloads get somewhat large.
Here is an example that reproduces this, it works if the payload is smaller, say 200000000 bytes. But if you increase it to 300000000 it will fail.


	MemoryBlock payload(300000000, true); //change it to 200000000 and it works, but 300000000 causes the problem
	String plainString = payload.toBase64Encoding();

    MemoryOutputStream stream;
    stream.writeString(plainString);
    stream.flush();
    MemoryBlock plaintext = stream.getMemoryBlock();
	String b64 = plaintext.toBase64Encoding();
	MemoryBlock decoded;
    decoded.fromBase64Encoding(b64);
	if (plaintext != decoded)
		std::cout << "not matching" << std::endl;
	else
		std::cout << "match" << std::endl;

I don’t know why it fails, but why would you have almost 300 MB worth of data base64 encoded in the first place?

well, i know it’s an edge case. But sometimes due to user input it leads to that

uint32 wrapping around or even int32 overflowing into undefined behaviour ?

Thanks for reporting, fixed here:

great, thanks!