Skip to content

Investigate OutOfMemory Exception happening woth Regex.Match for some patterns in the interpreted engine. #63385

Closed

Description

@joperezr

There are some Regex pattern and input pairs that can trigger an OOM Exception with the Interpreted engine only. The issue seems to be that these crafted inputs are causing the interpreted engine to fail to exit out from a loop and increment the size of runstack array on RegexRunner until eventually an OOM happens. This doesn’t repro on the Compiled, NonBacktracking or source generated engines.

One example pattern that can be problematic is (|)+?$ which can repro with pretty much all non empty inputs, for example 11.

This issue is to track the investigation and resolution of this issue.

Activity

  1. added this to the 7.0.0 milestone on Jan 5, 2022
  2. ghost added
    untriaged
    on Jan 5, 2022
  3. removed
    untriaged
    on Jan 5, 2022
  4. self-assigned this
    on Jan 5, 2022
  5. joperezr commented on Jul 20, 2022

    @joperezr
    MemberAuthor

    I just tried this out in preview 7 and I can't seem to be able to reproduce the issue any longer, so I'll go ahead close this for now.

  6. stephentoub commented on Jul 21, 2022

    @stephentoub
    Member

    I just tried this out in preview 7 and I can't seem to be able to reproduce the issue any longer, so I'll go ahead close this for now.

    I can't repro it even on .NET 6. Are we sure the cited pattern / input are the right ones?

  7. stephentoub commented on Jul 21, 2022

    @stephentoub
    Member

    I believe this is still an issue. Try:

    using System;
    using System.Text.RegularExpressions;
    
    var r = new Regex(@"(^+?)?()");
    r.Match("1");
  8. joperezr commented on Aug 8, 2022

    @joperezr
    MemberAuthor

    You are right, that pattern does repro in both 7.0 and 6.0. Given this is not a regression from 6 and the limited time we have for 7.0, I'm adjusting the milestone.

  9. modified the milestones: 7.0.0, Future on Aug 8, 2022
  10. added
    in-pr
    on Oct 19, 2025
  11. locked and limited conversation to collaborators on Nov 19, 2025
  12. removed
    in-pr
    on Feb 4, 2026
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions