Skip to content
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

Regex Matches Count gives ArgumentOutOfRangeException (regression) #66212

Closed
AlbertoMonteiro opened this issue Mar 4, 2022 · 8 comments · Fixed by #66216
Closed

Regex Matches Count gives ArgumentOutOfRangeException (regression) #66212

AlbertoMonteiro opened this issue Mar 4, 2022 · 8 comments · Fixed by #66216

Comments

@AlbertoMonteiro
Copy link

AlbertoMonteiro commented Mar 4, 2022

Description

Just run this code with dotnet 7.0.100-preview.1.22110.4 and it will break

_ = Regex.Matches("bar\n", @"(?m)^[^a]a", 0).Count

image

Reproduction Steps

Clone this project: https://github.com/AlbertoMonteiro/RegexIssueDotnet7Preview1
Then dotnet run

Expected behavior

The Count should return 1

Actual behavior

Throws System.ArgumentOutOfRangeException

Regression?

On dotnet 6 it works fine

Known Workarounds

Adding an \0 to the end of the string that ends with \n doesnt throw

_ = Regex.Matches("bar\n\0", @"(?m)^[^a]a", 0).Count

Returns properly 1

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.RegularExpressions untriaged New issue has not been triaged by the area owner labels Mar 4, 2022
@ghost
Copy link

ghost commented Mar 4, 2022

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Just run this code with dotnet 7.0.100-preview.1.22110.4 and it will break

_ = Regex.Matches("bar\n", @"(?m)^[^a]a", 0).Count

image

Reproduction Steps

Clone this project: https://github.com/AlbertoMonteiro/RegexIssueDotnet7Preview1
Then dotnet run

Expected behavior

The Count should return 1

Actual behavior

Throws System.ArgumentOutOfRangeException

Regression?

On dotnet 6 it works fine

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: AlbertoMonteiro
Assignees: -
Labels:

area-System.Text.RegularExpressions, untriaged

Milestone: -

AlbertoMonteiro added a commit to AlbertoMonteiro/BlazorAppRegex that referenced this issue Mar 4, 2022
@stephentoub stephentoub added bug and removed untriaged New issue has not been triaged by the area owner labels Mar 4, 2022
@stephentoub stephentoub added this to the 7.0.0 milestone Mar 4, 2022
@stephentoub stephentoub self-assigned this Mar 4, 2022
@stephentoub
Copy link
Member

Thanks for the great bug report. We're missing a length check after we optimize for a beginning-of-line anchor and jump to the next \n.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 4, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 7, 2022
@firasdib
Copy link

For what its worth, I was unable to verify that this fix worked, running the nightly build (found here https://github.com/dotnet/aspnetcore/blob/main/docs/DailyBuilds.md). I still see the same error.

@stephentoub
Copy link
Member

I was unable to verify that this fix worked, running the nightly build (found here https://github.com/dotnet/aspnetcore/blob/main/docs/DailyBuilds.md). I still see the same error.

What version of the runtime is this using? The PR that fixed this issue added as tests the exact offending inputs:
https://github.com/dotnet/runtime/pull/66216/files#diff-c58e67b58388ef7fa39f05ef7548fd1a3af4473457a150cac9bebe1e8ad0dadbR247-R278

@firasdib
Copy link

This is the output I get is:

> ~/projects/dotnet/dotnet --version
7.0.100-preview.3.22165.3

Running Linux 5.16.11-2-MANJARO x86_64

@stephentoub
Copy link
Member

What do you see for .NET 7 for dotnet --list-runtimes?

@firasdib
Copy link

Here's the output from that

> ~/projects/dotnet/dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.0-preview.3.22158.12 [/home/firas/projects/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.0-preview.3.22151.6 [/home/firas/projects/dotnet/shared/Microsoft.NETCore.App]

@stephentoub
Copy link
Member

7.0.0-preview.3.22151.6

Thanks. This maps to https://github.com/dotnet/runtime/commits/2330b4bef645bf8bcd3011f35968e55192c697f5 from March 2nd, which doesn't include #66216 that was merged on March 6th. I'm not sure why the current nightly installer has a two-week old runtime.... @mmitche?

@ghost ghost locked as resolved and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants