PropertyGridView: Prevent out-of-range access when committing next enumerable value#14182
Open
LeafShi1 wants to merge 2 commits intodotnet:mainfrom
Open
PropertyGridView: Prevent out-of-range access when committing next enumerable value#14182LeafShi1 wants to merge 2 commits intodotnet:mainfrom
LeafShi1 wants to merge 2 commits intodotnet:mainfrom
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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
DoubleClickRowmethod before cycling through enumerable values - Added empty array validation in
OnMouseWheelmethod before cycling through enumerable values with mouse wheel
SimonZhao888
approved these changes
Jan 6, 2026
SimonZhao888
approved these changes
Jan 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DoubleClickRowandOnMouseWheel: After callinggridEntry.GetPropertyValueList(), checkvalues.Length > 0before trying to accessvalues[index].Customer Impact
Regression?
Risk
Screenshots
WinFormsApp18.zip
Before
Double‑clicking or scroll the mouse wheel in the attribute value editing box,
GetPropertyValueList()may return an empty arrayBeforeChanges.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
Test environment(s)
Microsoft Reviewers: Open in CodeFlow