Bug 7578 - Regex executed on thread throws StackOverflowException
Summary: Regex executed on thread throws StackOverflowException
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-10-01 18:18 UTC by Tom Hindle
Modified: 2014-11-23 23:03 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case showing bug. (186.20 KB, text/x-csharp)
2012-10-01 18:18 UTC, Tom Hindle
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Tom Hindle 2012-10-01 18:18:31 UTC
Created attachment 2666 [details]
Test case showing bug.

When I run his complicated regex on a large data set mono throws a StackOverflowException.

Unhandled Exception: System.StackOverflowException: The requested operation caused a stack overflow.
  at System.Text.RegularExpressions.Interpreter.EvalChar (Mode mode, System.Int32& ptr, System.Int32& pc, Boolean multi) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 
  at System.Text.RegularExpressions.Interpreter.Eval (Mode mode, System.Int32& ref_ptr, Int32 pc) [0x00000] in <filename unknown>:0 

Test case attached showing issue.
Comment 1 Tom Hindle 2012-10-01 18:40:19 UTC
It seems like the on the main thread the stack memory (or the amount of recursive calls needed to cause a stackoverflow) is much greater.

My simple testing shows that a simple static function that takes a single int parameter, can be called 260642 before a stackoverflow occurs on the main thread, whilst on a secondary thread a stackoverflow occurs on 31590 calls.

IE:
public static void Main(string[] args)
{
	// can be called 260642 on the main thread.			
	// MyFunc(1);

	// Can be called 31590 on a thread.
	Action a = () => MyFunc(1);
	IAsyncResult result = a.BeginInvoke(null,null);
	a.EndInvoke(result);
}

public static void MyFunc(int i)
{
	Console.WriteLine(i);
	MyFunc(i + 1);
}
Comment 2 Miguel de Icaza [MSFT] 2014-11-23 23:03:03 UTC
Fixed by importing .NET's code