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

An invalid parameter was passed to a function that considers invalid parameters fatal. Only when building in debug mode. #1243

Closed
artvabasDev opened this issue Oct 14, 2023 · 3 comments

Comments

@artvabasDev
Copy link

Like to report a debug build error, hopefully you can solve this, its a bit unhandy to develop an application when you're not able to build it for debugging,

Using cryptopp version 8.9 with Visual Studio 2022 in a MFC application.

When I build this piece of code in debug mode:

void SomeClass::EncryptString(CString& str)
{

AutoSeededRandomPool rng;

// Generate private key
RSA::PrivateKey privateKey;
privateKey.GenerateRandomWithKeySize(rng, 2048);
RSA::PublicKey publicKey(privateKey);

std::string plain = CW2A(str), cipher, recovered;

// Encryption
RSAES_OAEP_SHA_Encryptor e(publicKey);

StringSource ss1(plain, true,
new PK_EncryptorFilter(rng, e,
new StringSink(cipher)
) // PK_EncryptorFilter
); // StringSource
}

When executing line: privateKey.GenerateRandomWithKeySize(rng, 2048); I got the following debug message:

Unhandled exception at 0x00007FF73F1F31FC An invalid parameter was passed to a function that considers invalid parameters fatal.

And Visual Studio 2022 is showing:

extern "C" __declspec(noreturn) void __cdecl _invoke_watson(
wchar_t const* const expression,
wchar_t const* const function_name,
wchar_t const* const file_name,
unsigned int const line_number,
uintptr_t const reserved
)
{
UNREFERENCED_PARAMETER(expression );
UNREFERENCED_PARAMETER(function_name);
UNREFERENCED_PARAMETER(file_name );
UNREFERENCED_PARAMETER(line_number );
UNREFERENCED_PARAMETER(reserved );

    if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
    {
        __fastfail(FAST_FAIL_INVALID_ARG);
    }

    // Otherwise, raise a fast-fail exception and termintae the process:
    __acrt_call_reportfault(
        _CRT_DEBUGGER_INVALIDPARAMETER,
        STATUS_INVALID_CRUNTIME_PARAMETER,
        EXCEPTION_NONCONTINUABLE);

    TerminateProcess(GetCurrentProcess(), STATUS_INVALID_CRUNTIME_PARAMETER);
}

And stop at: __fastfail(FAST_FAIL_INVALID_ARG);.

While the same piece of code when building in release mode is working just fine.

I use the debug version of cryptlib.lib for building in debug mode and the release version for building in release mode.

@noloader
Copy link
Collaborator

noloader commented Oct 16, 2023

I can't duplicate with the following program built with -DDEBUG -g3 -O0. The library was also built with the same flags.

$ cat test.cxx 
#include "cryptlib.h"
#include "osrng.h"
#include "rsa.h"

int main(int argc, char* argv[])
{
  using namespace CryptoPP;

  AutoSeededRandomPool prng;
  RSA::PrivateKey privateKey;
  privateKey.GenerateRandomWithKeySize(prng, 2048);
  RSA::PublicKey publicKey(privateKey);

  return 0;
}

There's probably something wrong with your program.

@artvabasDev
Copy link
Author

Still strange that the same code in release is working just fine and in debug not.
Have a workaround now, in debug using plain text in release encrypted.

Thanks for you effort.

@noloader
Copy link
Collaborator

I experienced this issue about 8 or 10 years ago on OS X. If I recall correctly, there was a global static, and for some reason, it was triggering the unused parameter exception. I never figured out what was sideways.

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

2 participants