-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix integer overflow in ArrayList.IListWrapper.BinarySearch and improve test coverage #123806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9bafa1f
f1ac6d4
3040bd0
f9c7238
e5ac50f
0ecedca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -768,10 +768,9 @@ public override int BinarySearch(int index, int count, object? value, IComparer? | |
|
|
||
| int lo = index; | ||
| int hi = index + count - 1; | ||
| int mid; | ||
| while (lo <= hi) | ||
| { | ||
| mid = (lo + hi) / 2; | ||
| int mid = lo + ((hi - lo) >> 1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot, do any other types in this repo have a similar overflow risk?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 3 additional locations with similar overflow risk using
All other binary search implementations in System.Private.CoreLib (Array.cs, ArraySortHelper.cs, List via ArraySortHelper) already use the safe pattern Should I file separate issues for the ConcurrentSet instances, or would you prefer I fix them in this PR? |
||
| int r = comparer.Compare(value, _list[mid]); | ||
| if (r == 0) | ||
| return mid; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.