Browse Source

fix: very large case

Akeit0 6 months ago
parent
commit
3f6acf5626
2 changed files with 9 additions and 3 deletions
  1. 1 1
      src/Lua/Internal/Constants.cs
  2. 8 2
      src/Lua/Runtime/LuaVirtualMachine.cs

+ 1 - 1
src/Lua/Internal/Constants.cs

@@ -8,5 +8,5 @@ internal class Constants
     public const int MaxStack = 1000000;
     public const int MaxUpValue = byte.MaxValue;
     public const int MaxCallCount = 200;
-    public const int MaxLine = 10000;
+    public const int MaxLine = 1000000;
 }

+ 8 - 2
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -1449,10 +1449,16 @@ public static partial class LuaVirtualMachine
         var count = instruction.B == 0
             ? stack.Count - (RA + 1)
             : instruction.B;
+        var c = instruction.C;
+        if (c == 0)
+        {
+            context.Pc++;
+            c =  context.Prototype.Code [context.Pc].Ax;
+        }
 
-        table.EnsureArrayCapacity((instruction.C - 1) * 50 + count);
+        table.EnsureArrayCapacity((c-1) * 50 + count);
         stack.GetBuffer().Slice(RA + 1, count)
-            .CopyTo(table.GetArraySpan()[((instruction.C - 1) * 50)..]);
+            .CopyTo(table.GetArraySpan()[((c- 1) * 50)..]);
         stack.PopUntil(RA + 1);
     }