Wei Dai wrote:
This code looks fine and works for me with the current Crypto++ code in 
CVS.

What version of Crypto++ are you using? And also I need a stack trace. 
After the debugger breaks at the exception, hit Alt-7 to open a call stack 
window and copy the information for me.

On Thu, Jun 24, 2004 at 06:47:09PM +0300, Cornel Maftuleac wrote:
  
Hello everybody.
I have discovered strange errors when working with 
StreamTransformationFilter class.
If something is wrong in the following example please correct me.
(OS: WinNT, Compiler: VC6.0)
The follofing example throws exception when returning from main()


//compiled with Debug Multithreaded DLL
#include <cryptopp/dll.h>
using namespace CryptoPP;
extern "C"
{
    void __declspec( dllexport ) GetNewAndDeleteForCryptoPP(PNew &pnew, 
PDelete &pdelete)
    {
        pnew = malloc;
        pdelete = free;
    }
}

int main()
{
    AutoSeededRandomPool rng;
    unsigned char m_Key[DES::DEFAULT_KEYLENGTH];
    unsigned char m_iv[DES::BLOCKSIZE];
    rng.GenerateBlock(m_Key,sizeof(m_Key));
    rng.GenerateBlock(m_iv,sizeof(m_iv));

    std::string EncryptionBuffer;
    ECB_Mode<DES>::Encryption 
    ChiperEncrypt(m_Key,DES::DEFAULT_KEYLENGTH,m_iv);
    StreamTransformationFilter STFilterEncrypt(ChiperEncrypt,new 
    StringSink(EncryptionBuffer));
   
    unsigned char plaintext[] = "test bla bla bla";

    STFilterEncrypt.Put(plaintext,sizeof(plaintext));
    STFilterEncrypt.MessageEnd();

    //well it should exit here without problems I guess ...  :)
    return 0;
}
    



  


The exception occurs when the "std::string EncryptionBuffer" is destructed, in this example on exit.
Try using dynamic std::string instead of stack, and the exception will occur allso on destructor.
Using CryptoPP Version 5.1 3/20/2003

Call stack:
NTDLL! 77fa144b()
NTDLL! 77fb6bcc()
NTDLL! 77f81d44()
KERNEL32! 7c4fb252()
_CrtIsValidHeapPointer(const void * 0x002f41e8) line 1697
_free_dbg_lk(void * 0x002f41e8, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x002f41e8, int 1) line 1001 + 13 bytes
free(void * 0x002f41e8) line 956 + 11 bytes
operator delete(void * 0x002f41e8) line 7 + 9 bytes
std::allocator<char>::deallocate(void * 0x002f41e8, unsigned int 33) line 64 + 38 bytes
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(unsigned char 1) line 592
std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() line 59 + 39 bytes
main() line 33 + 62 bytes
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 7c4e87f5()

Reply via email to