Skip to content

Fix GetUserString DEBUG validation to use length-bounded string construction - #127620

Merged
max-charlamb merged 1 commit into
mainfrom
cdac-fix-dump-test-failure
May 1, 2026
Merged

max-charlamb merged 1 commit into
mainfrom
cdac-fix-dump-test-failure

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Apr 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes a DEBUG assertion failure in the cDAC GetUserString validation introduced in #127471.

This failure wasn't in the method implementation but the validation logic. With this fix the runtime-diagnostics SOS test runs are clean.

Problem

The GetUserString implementation correctly matches native behavior by not null-terminating its output buffer when the string fits without truncation. However, the DEBUG validation block used new string(char*) which reads until a null terminator, potentially reading garbage bytes past the actual string data.

This caused assertion failures in SOS integration tests:

UserString content mismatch: cDAC='ThrowExceptionA', DAC='ThrowException'

The extra A character came from whatever followed the string in the caller's buffer.

Fix

Use length-bounded string construction new string(char*, 0, length) with the known character count instead of relying on null termination. This is safe regardless of the buffer's contents past the written characters.

…ruction

GetUserString does not null-terminate its output buffer (matching native
behavior). The DEBUG validation was using new string(char*) which reads
until a null terminator, potentially reading garbage past the actual
string data. This caused assertion failures like:
  UserString content mismatch: cDAC='ThrowExceptionA', DAC='ThrowException'

Fix by using new string(char*, 0, length) with the known character count,
which is safe regardless of whether the buffer is null-terminated.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a DEBUG-only validation bug in the cDAC IMetaDataImport.GetUserString parity checks by avoiding null-terminated string construction for buffers that are intentionally not null-terminated (to match native behavior).

Changes:

  • Replaces new string(char*) with length-bounded new string(char*, int startIndex, int length) in the DEBUG validation block for GetUserString.
  • Adds an explanatory comment and computes a safe comparison length based on the legacy-reported character count and the caller’s buffer size.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@max-charlamb
max-charlamb merged commit e1703cf into main May 1, 2026
66 of 70 checks passed
@max-charlamb
max-charlamb deleted the cdac-fix-dump-test-failure branch May 1, 2026 05:06
@github-actions github-actions Bot locked and limited conversation to collaborators May 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants