Skip to content

Fix issue 134653 - #134696

Open
rcj1 wants to merge 4 commits into
dotnet:mainfrom
rcj1:fix-134653
Open

rcj1 wants to merge 4 commits into
dotnet:mainfrom
rcj1:fix-134653

Conversation

@rcj1

@rcj1 rcj1 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #134653

The optimized DFA loop transitioned on the boundary character before returning to perform a timeout check, but did not advance the input position. If the transition succeeded but the chunk boundary had been reached, the next loop processed that character a second time, which could cause subsequent matches to be missed.

Ensure that our position is incremented if and only if we have made a successful transition.

Added regression coverage for inputs containing 150,000 and 400,000 padding characters. The tests verify that both occurrences of  foo  are returned when using  RegexOptions.NonBacktracking  with a finite timeout.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@rcj1
rcj1 marked this pull request as ready for review September 26, 2026 03:11
@rcj1
rcj1 requested a review from jkotas September 26, 2026 03:12
@jkotas
jkotas requested a balanced review from Copilot September 26, 2026 03:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The reordered condition skips the final input character, causing matches ending at EOF to be missed.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Attempts to prevent duplicate DFA processing at finite-timeout chunk boundaries.

Changes:

  • Reorders the optimized DFA boundary check.
  • Adds large-input regression coverage.
File Description
SymbolicRegexMatcher.cs Adjusts DFA boundary handling.
Regex.MultipleMatches.Tests.cs Tests matches across timeout-check boundaries.

@rcj1

rcj1 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Performance (win x64):

Regex NonBacktracking Performance Results

Type Method Job Toolchain Pattern Options Mean Error StdDev Median Min Max Ratio RatioSD Allocated Alloc Ratio
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe \s[a-zA-Z]{0,12}ing\s NonBacktracking 4,226.67 us 283.929 us 326.973 us 4,179.70 us 3,941.35 us 5,483.5 us 1.00 0.00 2642 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe \s[a-zA-Z]{0,12}ing\s NonBacktracking 4,229.17 us 279.241 us 321.574 us 4,146.89 us 3,975.02 us 5,427.6 us 1.01 0.10 2642 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe \w+\s+Holmes NonBacktracking 3,828.95 us 257.057 us 296.027 us 3,771.96 us 3,528.18 us 4,911.2 us 1.00 0.00 676 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe \w+\s+Holmes NonBacktracking 3,799.69 us 232.941 us 268.255 us 3,741.79 us 3,585.43 us 4,794.1 us 1.00 0.09 676 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe \w+\s+Holmes\s+\w+ NonBacktracking 3,802.51 us 275.542 us 317.314 us 3,707.98 us 3,618.19 us 5,089.1 us 1.00 0.00 990 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe \w+\s+Holmes\s+\w+ NonBacktracking 3,812.99 us 259.930 us 299.336 us 3,751.50 us 3,569.24 us 4,996.8 us 1.01 0.10 990 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe Sherlock|Holmes NonBacktracking 204.56 us 17.252 us 19.868 us 197.02 us 187.15 us 251.7 us 1.00 0.00 44 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe Sherlock|Holmes NonBacktracking 190.95 us 15.879 us 18.286 us 182.18 us 172.30 us 230.3 us 0.94 0.12 41 B 0.93
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe Sherlock|Holmes|Watson NonBacktracking 279.18 us 24.430 us 28.133 us 268.08 us 252.38 us 358.8 us 1.00 0.00 71 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe Sherlock|Holmes|Watson NonBacktracking 250.81 us 16.890 us 19.451 us 244.24 us 231.04 us 297.0 us 0.91 0.10 78 B 1.10
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe Sherlock|Holm(...)er|John|Baker [45] NonBacktracking 2,276.45 us 161.183 us 185.618 us 2,188.16 us 2,110.85 us 2,841.7 us 1.00 0.00 1369 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe Sherlock|Holm(...)er|John|Baker [45] NonBacktracking 2,282.99 us 155.278 us 178.818 us 2,239.86 us 2,127.75 us 2,979.1 us 1.01 0.11 1369 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-IHEKPC \main\corerun.exe Sherlock|Street NonBacktracking 91.30 us 8.146 us 9.380 us 87.43 us 83.71 us 111.9 us 1.00 0.00 13 B 1.00
Perf_Regex_Industry_RustLang_Sherlock Count Job-ZFARSF \pr\corerun.exe Sherlock|Street NonBacktracking 91.34 us 8.072 us 9.296 us 87.24 us 83.96 us 111.2 us 1.01 0.13 13 B 1.00
Perf_Regex_Industry_Leipzig Count Job-IHEKPC \main\corerun.exe .{0,2}(Tom|Sawyer|Huckleberry|Finn) NonBacktracking 95,765.01 us 4,678.064 us 5,387.265 us 95,685.95 us 87,514.90 us 109,475.0 us 1.00 0.00 287936 B 1.00
Perf_Regex_Industry_Leipzig Count Job-ZFARSF \pr\corerun.exe .{0,2}(Tom|Sawyer|Huckleberry|Finn) NonBacktracking 96,060.03 us 7,817.591 us 9,002.750 us 94,343.55 us 88,602.90 us 129,176.6 us 1.01 0.11 287936 B 1.00
Perf_Regex_Industry_Leipzig Count Job-IHEKPC \main\corerun.exe .{2,4}(Tom|Sawyer|Huckleberry|Finn) NonBacktracking 95.24 ms 9.992 ms 11.506 ms 96.78 ms 64.33 ms 122.2 ms 1.00 0.00 141.21 KB 1.00
Perf_Regex_Industry_Leipzig Count Job-ZFARSF \pr\corerun.exe .{2,4}(Tom|Sawyer|Huckleberry|Finn) NonBacktracking 98.16 ms 7.589 ms 8.740 ms 96.24 ms 89.64 ms 128.6 ms 1.05 0.17 141.21 KB 1.00

@jkotas
jkotas requested review from a team and a balanced review from Copilot September 27, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

A failed DFA transition on the final character can loop indefinitely instead of switching to NFA mode.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegexOptions.NonBacktracking with a finite match timeout misses matches on inputs over ~100k characters

3 participants