JavaScript: source that eval and Function compile takes fuel before it is parsed

Direct and indirect eval, Function and host evaluators parsed and compiled
their source before taking any fuel or checking the heap, so a script with a
small fuel limit could make the interpreter parse megabytes of source in a
handful of instructions. Interp::prepare_source now takes one unit of fuel for
each UTF-16 code unit and checks that the source text fits in the heap before
the source is flattened, parsed or compiled. A host evaluator's string takes
the fuel for a third of its bytes before it is encoded, and the rest after.

Limits::fuel and the maxFuel row in docs/mcp.md say so.
This commit is contained in:
dotCooCoo
2026-11-11 19:52:06 -08:00
parent 6b8be09699
commit d151f3f5d0
7 changed files with 76 additions and 8 deletions
+1 -1
View File
@@ -1826,7 +1826,7 @@ VectorCraft sets these limits itself:
| Included and evaluated files | 64 in all, 16 levels deep, 1,024 paths looked up |
| Heap | 256 MiB (128 MiB on the web) |
| Host calls | 2,000,000 |
| `maxFuel`, instructions in all | 1 to 100,000,000,000; 1,000,000,000 by default |
| `maxFuel`, instructions in all, plus one for each UTF-16 code unit of source that `eval`, `Function` or an evaluated file compiles during the run | 1 to 100,000,000,000; 1,000,000,000 by default |
| Instructions without a pause | 200,000,000 |
| Nesting depth | 64 levels |
| A value crossing to or from a command | 16 MiB and 1,048,576 entries |