Form Script Budgets

Every form-script evaluation runs under strict budgets covering CPU time, memory, recursion depth, statement and operation counts, and the output a script may generate, so a runaway calculation can never stall a recalculation pass or exhaust memory

THPDFScriptBudgets

THotPDF.FormScriptBudgets holds the budget set applied by EvaluateLoadedFieldJavaScript and by every recalculation pass. The THPDFScriptBudgets record exposes MaxScriptLength, MaxStatements, MaxExpressionDepth, MaxOperations, MaxElapsedMilliseconds (wall-clock CPU cutoff), MaxValueBytes (single-value cap), MaxTotalValueBytes (cumulative memory), and MaxOutputBytes (generated-output cap); zero in any field lifts that specific limit

var
  Budgets: THPDFScriptBudgets;
begin
  Budgets:= PDF.FormScriptBudgets;
  Budgets.MaxElapsedMilliseconds:= 100;
  Budgets.MaxTotalValueBytes:= 1024* 1024;
  PDF.FormScriptBudgets:= Budgets;
end;

Enforcement and telemetry

The CPU cutoff is checked while operations and value bytes accumulate, so scripts cannot bypass it through allocation alone; the cumulative memory budget catches scripts that allocate and discard many small values. A breach fails the evaluation with a descriptive ErrorText and the result record reports ElapsedMilliseconds and ValueBytes telemetry alongside the operation count

The default budgets keep the historical limits (8192-byte scripts, 32 statements, depth 32, 1024 operations, 256 KB per value) and add a 500 ms CPU cutoff, a 4 MB cumulative memory budget, and a 64 KB output cap