Skip to content

IndexOutOfRangeException when using compiled and ignorecase regex in .NET 7.0 #79298

Closed

Description

@Nuklon

Description

Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Regex1_TryMatchAtCurrentPosition(RegexRunner, ReadOnlySpan`1)
   at Regex1_Scan(RegexRunner, ReadOnlySpan`1)
   at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan`1 span, Boolean returnNullIfReuseMatchObject)
   at System.Text.RegularExpressions.Regex.RunSingleMatch(RegexRunnerMode mode, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat)
   at System.Text.RegularExpressions.Regex.IsMatch(String input)
   at Program.Main()

Reproduction Steps

   var regex = new Regex(@"(ver\.? |[_ ]+)?\d+(\.\d+){2,3}$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
   Console.WriteLine(regex.IsMatch(" Ver 2.0")); // Throws (you can add anything before Ver, but something must exists).

Expected behavior

No throw.

Actual behavior

Throws.

Regression?

Yes, works in .NET 6.0 and .NET Framework.

Known Workarounds

No response

Configuration

.NET 7.0.
Windows 10 22H2
x64
Happens on Linux too.

Other information

No response

Activity

  1. ghost added
    untriaged
    on Dec 6, 2022
  2. added and removed
    untriaged
    on Dec 6, 2022
  3. self-assigned this
    on Dec 6, 2022
  4. ghost added
    in-pr
    on Dec 7, 2022
  5. stephentoub commented on Dec 7, 2022

    @stephentoub
    Member

    Thanks for the helpful repro. I've put up a fix in #79353.

  6. added this to the 8.0.0 milestone on Dec 7, 2022
  7. ghost removed
    in-pr
    on Dec 7, 2022
  8. Nuklon commented on Dec 8, 2022

    @Nuklon
    Author

    Thanks for the fix @stephentoub and also for the backport as this prevents me from upgrading.

  9. stephentoub commented on Dec 8, 2022

    @stephentoub
    Member

    Thanks for the fix @stephentoub and also for the backport as this prevents me from upgrading.

    You're welcome. Would you be able to try it out and validate your issue is entirely addressed?

  10. Nuklon commented on Dec 10, 2022

    @Nuklon
    Author

    I can give it a try if it's in the daily build, I'm not sure it is yet?

  11. buyaa-n commented on Dec 21, 2022

    @buyaa-n
    Contributor

    It should have included in daily build already

  12. ghost locked as resolved and limited conversation to collaborators on Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions