Skip to content

PropertyGridView: Prevent out-of-range access when committing next enumerable value - #14182

Merged
LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14170_add_protection_in_DoubleClickRow
Aug 31, 2026
Merged

LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14170_add_protection_in_DoubleClickRow

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Jan 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #14169
Fixes #14170

Root cause:

The PropertyGrid assumes that the StandardValues list is stable and non‑empty once the current index is computed.
However, during both double‑click value cycling and mouse‑wheel value cycling, the control calls GetPropertyValueList() a second time when committing the next value.
In certain scenarios (dynamic TypeConverters, context‑dependent StandardValues, or volatile data sources), this second call may return an empty array, making the previously computed index invalid.
This leads to an out‑of‑range access when executing:

CommitValue(values[index])

Proposed changes

  • Update method DoubleClickRow and OnMouseWheel: After calling gridEntry.GetPropertyValueList(), check values.Length > 0 before trying to access values[index].

Customer Impact

  • Prevents IndexOutOfRangeException or similar crashes when users double‑click or scroll a PropertyGrid entry whose StandardValues list becomes empty at commit time.

Regression?

  • No

Risk

  • Minimal

Screenshots

WinFormsApp18.zip

Before

Double‑clicking or scroll the mouse wheel in the attribute value editing box, GetPropertyValueList() may return an empty array

BeforeChanges.mp4

After

Logic re‑verifies the StandardValues list before using it.
If values.Length == 0, cycling is safely skipped.
No exceptions are thrown

AfterChanges.mp4

Test methodology

  • Manually

Test environment(s)

  • .net 11.0.0-alpha.1.25619.109
Microsoft Reviewers: Open in CodeFlow

@codecov

codecov Bot commented Jan 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.14364%. Comparing base (05b7c2e) to head (6873346).
⚠️ Report is 106 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14182         +/-   ##
===================================================
- Coverage   77.15877%   77.14364%   -0.01513%     
===================================================
  Files           3279        3279                 
  Lines         645333      645339          +6     
  Branches       47720       47722          +2     
===================================================
- Hits          497931      497838         -93     
- Misses        143719      143813         +94     
- Partials        3683        3688          +5     
Flag Coverage Δ
Debug 77.14364% <0.00000%> (-0.01513%) ⬇️
integration 18.99429% <0.00000%> (-0.00981%) ⬇️
production 51.99632% <0.00000%> (-0.03339%) ⬇️
test 97.40559% <ø> (ø)
unit 49.43828% <0.00000%> (-0.00416%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This PR fixes IndexOutOfRangeException crashes in PropertyGridView when users double-click or scroll with the mouse wheel on enumerable properties whose StandardValues list becomes empty between index calculation and value commit. The fix adds defensive checks to ensure the values array is not empty before attempting to access it by index.

Key Changes:

  • Added empty array validation in DoubleClickRow method before cycling through enumerable values
  • Added empty array validation in OnMouseWheel method before cycling through enumerable values with mouse wheel

@ricardobossan ricardobossan left a comment

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.

All LGTM!

@LeafShi1 LeafShi1 added the waiting-review This item is waiting on review by one or more members of team label Apr 22, 2026
@LeafShi1
LeafShi1 merged commit 6288b31 into dotnet:main Aug 31, 2026
13 of 14 checks passed
@dotnet-policy-service dotnet-policy-service Bot removed the waiting-review This item is waiting on review by one or more members of team label Aug 31, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 1, 2026
abineshPalanisamy pushed a commit to abineshPalanisamy/winforms that referenced this pull request Sep 3, 2026
…umerable value (dotnet#14182)

## Proposed changes

- Update method `DoubleClickRow` and `OnMouseWheel`: After calling `gridEntry.GetPropertyValueList()`, check `values.Length > 0` before trying to access `values[index]`.

## Customer Impact

- Prevents IndexOutOfRangeException or similar crashes when users double‑click or scroll a PropertyGrid entry whose StandardValues list becomes empty at commit time.
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 1, 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.

PropertyGrid: PropertyGridView.DoubleClickRow - IndexOutOfRangeException PropertyGrid: PropertyGridView.OnMouseWheel - IndexOutOfRangeException

5 participants