Skip to content

AccessViolationException in class constructors #34

@fuzzah

Description

@fuzzah

After instrumenting my code with SharpFuzz I get constant System.AccessViolationExceptions even without fuzzing.
I don't know what exactly causes it, but it seems to always happen in constructors.
I have prepared a tiny reproducer app.

Reproduce:

  1. Download the attached reproduce.tar.gz archive. It contains the source code for two projects: the FuzzMe is an application under test and the FuzzMe.Fuzz is the fuzzing harness.
  2. Extract the archive: tar zxvf reproduce.tar.gz
  3. [Review the code]
  4. Build the FuzzMe.Fuzz app. No errors should pop up:
cd reproduce/tests/FuzzMe.Fuzz
dotnet publish -c Release --self-contained -r linux-x64
  1. Make sure the FuzzMe.Fuzz app raises no exceptions:
echo test | ./bin/Release/net6.0/linux-x64/FuzzMe.Fuzz
  1. Instrument FuzzMe* classes within the FuzzMe.dll with SharpFuzz:
export SHARPFUZZ_PRINT_INSTRUMENTED_TYPES=1
sharpfuzz ./bin/Release/net6.0/linux-x64/FuzzMe.dll FuzzMe

It should print:

FuzzMe.Parser
FuzzMe.Point
FuzzMe.Program
  1. Run the app again and observe the exception:
echo test | ./bin/Release/net6.0/linux-x64/FuzzMe.Fuzz

The output looks like this:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at FuzzMe.Point..ctor(Int32, Int32)
   at FuzzMe.Fuzz.Program.Main(System.String[])
Aborted (core dumped)

The exit code is 134.

The SharpFuzz dependency is 2.0.1 and the SharpFuzz.CommandLine tool is also 2.0.1.

There are private/protected readonly fields in the constructors of Point and Parser classes, but changing them to public (and without readonly) changes nothing.

Is there some limitation in SharpFuzz regarding constructors? The real code I wish to test has lots of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions