SHA256 release build failing

15 views
Skip to first unread message

Farukh Sharipov

unread,
May 11, 2017, 4:31:41 PM5/11/17
to Crypto++ Users
Hi 


I have code below for the SHA256 implementation it compiles and works fine in Debug but when switched to Release configuration it fails with following message: 

Exception thrown at 0x4296339C (cryptopp.dll) in CryptoppCPP.exe: 0xC0000005: Access violation reading location 0x6F57206F.
If there is a handler for this exception, the program may be safely continued.

Crypto++ v5.3.0 FIPS
VS2015 Visual C++ 2015
Below is C++ Command Line: 

 
/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MT /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\CryptoppCPP.pch"

Linker Command Line: 

/OUT:"C:\Users\821973\Documents\Visual Studio 2015\Projects\CryptoppCPP\Release\CryptoppCPP.exe" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"C:\Users\821973\Documents\Visual Studio 2015\Projects\CryptoppCPP\Release\CryptoppCPP.pdb" /DYNAMICBASE "C:\Users\821973\Documents\Visual Studio 2015\Projects\CryptoppCPP\libs\x86\cryptopp.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /OPT:REF /SAFESEH /INCREMENTAL:NO /PGD:"C:\Users\821973\Documents\Visual Studio 2015\Projects\CryptoppCPP\Release\CryptoppCPP.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Release\CryptoppCPP.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

CPP

#include "main.h"
using namespace std;

USING_NAMESPACE
(CryptoPP)

#ifdef CRYPTOPP_IMPORTS

static PNew s_pNew = NULL;
static PDelete s_pDelete = NULL;


extern "C" __declspec(dllexport) void __cdecl SetNewAndDeleteFromCryptoPP(PNew pNew, PDelete pDelete, PSetNewHandler pSetNewHandler)
{
 s_pNew
= pNew;
 s_pDelete
= pDelete;
}


void * __cdecl operator new (size_t size)
{
 
return s_pNew(size);
}


void __cdecl operator delete (void * p)
{
 s_pDelete
(p);
}


#endif


int main()
{
 std
::cout << "Crypto++ Example" << endl;


 SHA256 hash
;
 
string message = "abcdefghijklmnopqrstuvwxyz";
 
string digest;


 
StringSource s(message, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));


 cout
<< digest << endl;
 


 system
("pause");


 
return 0;
}

H

#pragma once
#ifndef __SPDCRYPTO_H
#define __SPDCRYPTY_H
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <iostream>


#include "Include\dll.h"
#  pragma comment ( lib, "cryptopp" )
#endif


Does anyone came across this issue before? How can I track what could be causing this issue?

Thank you. 

Jeffrey Walton

unread,
May 11, 2017, 7:53:03 PM5/11/17
to Crypto++ Users


Does anyone came across this issue before? How can I track what could be causing this issue?

Farukh Sharipov

unread,
May 12, 2017, 12:43:08 PM5/12/17
to Crypto++ Users
Thank you Jeffrey 

I do know how to use debugger and google :). 

Since issue is coming up in Release and not Debug I can't step inside the Crypto++ it just breaks on this line: 

StringSource s(message, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));

Best Regards
Farukh Sharipov

Farukh Sharipov

unread,
May 12, 2017, 1:20:12 PM5/12/17
to Crypto++ Users
It breaks inside secblock.h line: 288


 void Assign(const T *t, size_type len)
 
{
 
New(len);
 memcpy_s
(m_ptr, m_size*sizeof(T), t, len*sizeof(T)); //<--BREAKS HERE
 
}

Jeffrey Walton

unread,
May 12, 2017, 2:41:59 PM5/12/17
to Crypto++ Users


On Friday, May 12, 2017 at 12:43:08 PM UTC-4, Farukh Sharipov wrote:
Thank you Jeffrey 

I do know how to use debugger and google :). 

Since issue is coming up in Release and not Debug I can't step inside the Crypto++ it just breaks on this line: 

StringSource s(message, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));

Just guessing...

On Windows and in the context of DLLs, you are ___not___ supposed to pass std::string (or other STL containers) through a DLL interface. You must use pointers and sizes. Here's one of Microsoft's old KB's about it: https://support.microsoft.com/en-us/help/813810 .

If you don't mind me asking, what is the aversion to providing the relevant source code and a stack trace? How do folks expect useful answers when the problem statement is "my DLL crashes" with no context and the question is "why".

Jeff
Reply all
Reply to author
Forward
0 new messages