sebastienros / jint

Javascript Interpreter for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Engine.Execute throws OutOfMemoryException after 45s (even with the 2s timeout)

Metalnem opened this issue · comments

The following program runs for about 45s (even though I've set the timeout interval to 2s) before finally throwing the OutOfMemoryException. You have to run in on .NET Framework 4.7.2 to reproduce it (this code hangs permanently on .NET Core, which I think is due to an issue in .NET Core itself).

using System;

namespace Jint.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      new Engine(SetOptions).Execute("'x'.match(/|/g);");
    }

    private static void SetOptions(Options options)
    {
      options.LimitRecursion(32).TimeoutInterval(TimeSpan.FromSeconds(2));
    }
  }
}

Here are the exception details:

System.OutOfMemoryException
  HResult=0x8007000E
  Message=Array dimensions exceeded supported range.
  Source=mscorlib
  StackTrace:
   at System.Collections.Generic.Dictionary`2.Resize(Int32 newSize, Boolean forceNewHashCodes)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Jint.Native.String.StringPrototype.Match(JsValue thisObj, JsValue[] arguments)
   at Jint.Runtime.Interop.ClrFunctionInstance.Call(JsValue thisObject, JsValue[] arguments)
   at Jint.Runtime.ExpressionInterpreter.EvaluateCallExpression(CallExpression callExpression)
   at Jint.Engine.ExecuteStatement(Statement statement)
   at Jint.Runtime.StatementInterpreter.ExecuteSingleStatement(Statement s)
   at Jint.Engine.Execute(Program program)

Found via SharpFuzz.

Thanks for reporting this, fixed via #626