-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Check regex timeout in loops and repetitions #38091
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,31 @@ public void Match_Timeout_Throws() | |
}).Dispose(); | ||
} | ||
|
||
// On 32-bit we can't test these high inputs as they cause OutOfMemoryExceptions. | ||
[ConditionalTheory(typeof(Environment), nameof(Environment.Is64BitProcess))] | ||
[InlineData(RegexOptions.Compiled)] | ||
[InlineData(RegexOptions.None)] | ||
public void Match_Timeout_Loop_Throws(RegexOptions options) | ||
{ | ||
var regex = new Regex(@"a\s+", options, TimeSpan.FromSeconds(1)); | ||
string input = @"a" + new string(' ', 800_000_000) + @"b"; | ||
|
||
Assert.Throws<RegexMatchTimeoutException>(() => regex.Match(input)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we validate that the exception is thrown within some window of time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would have to have significant leeway (eg., within 2x or 3x) to account for vagaries of CI machines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see it's a second. Maybe within 30 sec? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming 800M will take much longer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 30 seconds, 1 minute, whatever we think is reasonable. My goal would just be that the test doesn't pass after the regex runs for an hour and then upon completion sees there was a timeout requested and throws :) |
||
} | ||
|
||
// On 32-bit we can't test these high inputs as they cause OutOfMemoryExceptions. | ||
[ConditionalTheory(typeof(Environment), nameof(Environment.Is64BitProcess))] | ||
[InlineData(RegexOptions.Compiled)] | ||
[InlineData(RegexOptions.None)] | ||
public void Match_Timeout_Repetition_Throws(RegexOptions options) | ||
{ | ||
int repetitionCount = 800_000_000; | ||
var regex = new Regex(@"a\s{" + repetitionCount+ "}", options, TimeSpan.FromSeconds(1)); | ||
string input = @"a" + new string(' ', repetitionCount) + @"b"; | ||
|
||
Assert.Throws<RegexMatchTimeoutException>(() => regex.Match(input)); | ||
} | ||
|
||
public static IEnumerable<object[]> Match_Advanced_TestData() | ||
{ | ||
// \B special character escape: ".*\\B(SUCCESS)\\B.*" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on the non-emit version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment wasn't address. Fine for this PR, but consider addressing it subsequently.