Skip to content

Fix incorrect field offsets when parsing ETW events with fixed-count array fields#2427

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-fixed-array-offset-issues
Draft

Fix incorrect field offsets when parsing ETW events with fixed-count array fields#2427
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-fixed-array-offset-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

ETW events using TraceLoggingUInt32FixedArray, TraceLoggingFloat32FixedArray, or any other fixed-count TraceLogging array type produced corrupted values for all fields following the first fixed array field. WPA parsed these correctly; TraceEvent did not.

Root cause

In RegisteredTraceEventParser.TdhEventParser.ParseFields, the fixed-count array path set arraySize = fixedCount (element count, e.g. 3) and passed that as the size argument to ArrayPayloadFetch. This stored the element count as the byte size on PayloadFetch.Size. Since OffsetOfNextField uses PayloadFetch.Size directly to advance past the field, every subsequent field was off by fixedCount * elementSize - fixedCount bytes (e.g., off by 9 bytes for a 3-element float32 array).

Fix

Replace the ArrayPayloadFetch call with FixedCountArrayPayloadFetch when fixedCount != 0. This existing helper correctly computes size = elementCount * element.Size before forwarding to ArrayPayloadFetch — the same pattern already used in EventPipeMetadata.cs.

// Before
propertyFetch = DynamicTraceEventData.PayloadFetch.ArrayPayloadFetch(
    arrayFieldOffset, propertyFetch, arraySize, fixedCount, projectCharArrayAsString: false);

// After
if (fixedCount != 0)
    propertyFetch = DynamicTraceEventData.PayloadFetch.FixedCountArrayPayloadFetch(
        arrayFieldOffset, propertyFetch, fixedCount, projectCharArrayAsString: false);
else
    propertyFetch = DynamicTraceEventData.PayloadFetch.ArrayPayloadFetch(
        arrayFieldOffset, propertyFetch, arraySize, 0, projectCharArrayAsString: false);

When processing ETW events with fixed-count array fields (e.g. from
TraceLoggingUInt32FixedArray / TraceLoggingFloat32FixedArray), the
PayloadFetch.Size was being set to the element count instead of the
total byte size. This caused OffsetOfNextField to advance by only
`fixedCount` bytes instead of `fixedCount * elementSize` bytes,
corrupting the offsets of all subsequent fields.

Fix: use FixedCountArrayPayloadFetch (which correctly computes
size = elementCount * element.Size) instead of ArrayPayloadFetch
when fixedCount != 0, matching the pattern already used in
EventPipeMetadata.cs.

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parsing issues for fixed array data arguments Fix incorrect field offsets when parsing ETW events with fixed-count array fields May 26, 2026
Copilot AI requested a review from brianrob May 26, 2026 19:59
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.

Events with fixed array data arguments results in bad parsing (offset issues)

2 participants