I'm trying to decrypt a large map file passed as an argument, with given key and iv.
void decode(const QByteArray &input, const QByteArray &key, const QByteArray &iv)
{
using namespace CryptoPP;
std::string keyString(key.constData(), key.length());
std::string ivString(iv.constData(), iv.length());
std::string inputString(input.constData(), input.length());
try
{
std::basic_string<char> recovered = "";
recovered.reserve(1000);
CBC_Mode< AES >::Decryption d;
d.SetKeyWithIV((byte*)keyString.c_str(), keyString.size(), (byte*)ivString.c_str());
StringSource s(inputString, true,
new StreamTransformationFilter(d,
new StringSink(recovered)
) // StreamTransformationFilter
); // StringSource
}
catch (const Exception& e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
}
I've checked the result of the decryption stored inside recovered and it's correct, the result is as expected. The issue occurs though when the heap is being freed, when exiting the try catch block.
The following "heap has been corrupted" error is being prompted inside dll.cpp (from the cryptopp library) as I get out of the try catch block.
I've also tried avoiding the new keyword, but it doesn't seem to be related to this as I get the same error.
StringSink sink(recovered);
StreamTransformationFilter tFilter(d, &sink);
StringSource s(inputString, true, &tFilter);
Do you know why this might occur?
