Skip to content

Fix AccessViolation on malformed MethodILToNativeMap entry count - #2445

Merged
Brian Robbins (brianrob) merged 2 commits into
microsoft:mainfrom
brianrob:brianrob/ilmapping
Jul 22, 2026
Merged

Fix AccessViolation on malformed MethodILToNativeMap entry count#2445
Brian Robbins (brianrob) merged 2 commits into
microsoft:mainfrom
brianrob:brianrob/ilmapping

Conversation

@brianrob

@brianrob Brian Robbins (brianrob) commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

Fixes an uncatchable AccessViolationException (memory-safety / denial of service) on malformed EventPipe/ETW input in the TraceEvent library.

TraceLog.AddILMapping trusts CountOfMapEntries — a 16-bit count read from fully untrusted MethodILToNativeMap (EventID 190) event payload — when reading the per-entry ILOffset/NativeOffset values. Because NativeOffset(i) is indexed relative to CountOfMapEntries, a corrupt or fuzzed stream that claims more entries than the payload actually contains makes the reads index past the end of the event buffer and access protected memory, crashing the process with an AccessViolationException.

Reachable by any caller that parses untrusted data (e.g. TraceLog.CreateFromEventPipeDataFile).

How it was found

Discovered by the TraceEvent nettrace fuzzer.

Fix

  • Reject MethodILToNativeMap events whose payload is too small for the claimed entry count (a valid event has EventDataLength >= CountOfMapEntries * 8 + 21), and record the skip in the conversion log.
  • Add regression test MalformedILToNativeMapEntryCountDoesNotAccessViolation that drives the full TraceLog conversion path with such a malformed event and asserts it is rejected (deterministic; fails without the fix).

Brian Robbins (brianrob) and others added 2 commits July 19, 2026 20:17
TraceLog.AddILMapping trusted CountOfMapEntries, a 16-bit count read from fully
untrusted MethodILToNativeMap (EventID 190) event payload, when reading the
ILOffset/NativeOffset entries. Because NativeOffset(i) is indexed relative to
CountOfMapEntries, a corrupt or fuzzed EventPipe/ETW stream that claims more
entries than the payload actually contains caused the reads to index past the
end of the event buffer and access protected memory, crashing the process with
an (uncatchable) AccessViolationException. Found by the TraceEvent nettrace
fuzzer.

Reject events whose payload is too small for the claimed entry count (a valid
event has EventDataLength >= CountOfMapEntries * 8 + 21), record the skip in the
conversion log, and add a regression test that drives the full TraceLog
conversion path with such a malformed event.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7c1dc14b-deed-412d-bdca-a44a5ac9bf9a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b49ece18-cc2c-4ca2-8aff-82c7906a5518
@brianrob
Brian Robbins (brianrob) marked this pull request as ready for review July 22, 2026 19:34
@brianrob
Brian Robbins (brianrob) requested a review from a team as a code owner July 22, 2026 19:34
get { return Action; }
set { Action = (Action<MethodILToNativeMapTraceData>)value; }
}
internal override void FixupData()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is an override, do you need to call the method on base?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - it's just an empty method body.

@brianrob
Brian Robbins (brianrob) enabled auto-merge (squash) July 22, 2026 21:23
@brianrob
Brian Robbins (brianrob) merged commit 2d3da12 into microsoft:main Jul 22, 2026
5 checks passed
@brianrob
Brian Robbins (brianrob) deleted the brianrob/ilmapping branch July 22, 2026 21:43
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

Successfully merging this pull request may close these issues.

2 participants