Skip to content

Fix issue 14831: TaskDialogPage.GetBoundButtonByID throws IndexOutOfRangeException when TaskDialogIndirect returns unexpected button ID - #14842

Open
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14831
Open

Fix issue 14831: TaskDialogPage.GetBoundButtonByID throws IndexOutOfRangeException when TaskDialogIndirect returns unexpected button ID#14842
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14831

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes #14831

Root Cause

TaskDialogPage.GetBoundButtonByID and GetBoundRadioButtonByID map the ID returned by the native API directly to an array index without performing bounds checking.
If TaskDialogIndirect returns an ID outside the current page configuration during an abnormal closure (e.g., an ID in the "custom" range when no custom buttons are defined), an IndexOutOfRangeException is triggered, preventing the intended fallback logic from executing.

Proposed changes

  • Add bounds checking for the custom-button index in GetBoundButtonByID; return null if the index is out of bounds.
  • Add bounds checking for the radio-button index in GetBoundRadioButtonByID; return null if the index is out of bounds.
  • Handle the null return value in the TaskDialog TDN_RADIO_BUTTON_CLICKED callback to prevent potential dereferencing issues.
  • Add unit tests to cover the scenario where an out-of-bounds ID returns null instead of throwing an exception.

Customer Impact

  • Eliminated the risk of process crashes (IndexOutOfRangeException) in this code path.
  • Improved the robustness of TaskDialog when encountering exceptional or unexpected native return values, ensuring it correctly enters existing fault-tolerance branches.
  • Maintained the behavior of standard execution paths and public APIs, focusing solely on enhancing reliability and fault tolerance.

Regression?

  • No

Risk

  • Mini

Screenshots

Before

2026-08-04.142359.mp4

After

2026-08-04.142529.mp4

Test methodology

  • Manually
  • Automated test cases

Test environment(s)

  • 11.0.0-preview.7.26381.103

Test Project

TaskDialogIssue14831.zip

Microsoft Reviewers: Open in CodeFlow

…angeException when TaskDialogIndirect returns unexpected button ID
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.

TaskDialogPage.GetBoundButtonByID throws IndexOutOfRangeException when TaskDialogIndirect returns unexpected button ID

1 participant