Description
In string.IndexOf, when comparisonType is StringComparison.OrdinalIgnoreCase and startIndex + count causes an integer overflow, an ArgumentOutOfRangeException is not thrown. Instead, it returns an incorrect value.
If comparisonType is anything other than StringComparison.OrdinalIgnoreCase, ArgumentOutOfRangeException is is thrown.
Reproduction Steps
// comparisonType is StringComparison.OrdinalIgnoreCase
var result = "Hello".IndexOf('o', 1, int.MaxValue, StringComparison.OrdinalIgnoreCase); // return 4 (should throw ArgumentOutOfRangeException)
// comparisonType is StringComparison.Ordinal
var result = "Hello".IndexOf('o', 1, int.MaxValue, StringComparison.Ordinal); // throw ArgumentOutOfRangeException
Expected behavior
ArgumentOutOfRangeException is thrown.
Actual behavior
incorrect value is returned.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
This is an edge case, I have submitted a #128191
Description
In
string.IndexOf, when comparisonType isStringComparison.OrdinalIgnoreCaseandstartIndex + countcauses an integer overflow, anArgumentOutOfRangeExceptionis not thrown. Instead, it returns an incorrect value.If
comparisonTypeis anything other thanStringComparison.OrdinalIgnoreCase,ArgumentOutOfRangeExceptionis is thrown.Reproduction Steps
Expected behavior
ArgumentOutOfRangeExceptionis thrown.Actual behavior
incorrect value is returned.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
This is an edge case, I have submitted a #128191