Skip to content

"Bad PE Header" exception thrown on valid executable image #2316

@jggrant

Description

@jggrant

I have tried using PerfView to profile a rather large executable (I unfortunately cannot share), and I am encountering this exception found in the logs when trying to load its symbols:

An exception occurred during symbol lookup.  Continuing...
Exception: System.InvalidOperationException: Bad PE Header.
   at PEFile.PEHeader..ctor(Void* startOfPEFile)
   at PEFile.PEFile..ctor(String filePath)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceCodeAddresses.TraceModuleUnchanged(TraceModuleFile moduleFile, TextWriter log, String overrideModuleFilePath)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceCodeAddresses.OpenPdbForModuleFile(SymbolReader symReader, TraceModuleFile moduleFile)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceCodeAddresses.LookupSymbolsForModule(SymbolReader reader, TraceModuleFile moduleFile, IEnumerator`1 codeAddressIndexCursor, Boolean enumerateAll, Int32& totalAddressCount)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceCodeAddresses.LookupSymbolsForModule(SymbolReader reader, TraceModuleFile file)

After investigation, it is triggered by this check in the PEFile constructor:

if (!(sizeof(IMAGE_DOS_HEADER) <= imageHeaderOffset && imageHeaderOffset <= 512))

I see imageHeaderOffset is 560 in my executable. It seems bumping the threshold might be a way to fix it, at least locally increasing it to 1024 did the trick.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions