Skip to content

docs(engine): correct the record on why the bucket_script expression bound exists - #117

Merged
xerj-org merged 1 commit into
mainfrom
fix/expr-bound-record
Aug 1, 2026
Merged

docs(engine): correct the record on why the bucket_script expression bound exists#117
xerj-org merged 1 commit into
mainfrom
fix/expr-bound-record

Conversation

@xerj-org

@xerj-org xerj-org commented Aug 1, 2026

Copy link
Copy Markdown
Owner

No functional change. Doc comments only.

The bound landed in #115 with three comments asserting that the bucket_script expression evaluator is consumed recursively and that an unauthenticated request can exhaust the stack and abort the process. That claim was corrected in the commit message before #115 merged, but not in the source, so main currently documents a crash no released version had.

What is actually on this tree: eval_script_expr is tokenize_scriptshunting_yardevaluate_rpn, three flat loops over a Vec, and ? is not a token at all (tokenize_script returns None on it). Measured with the bound removed, on a 2 MiB stack:

input result
80,001 bytes, 20,000 ternaries Ok(None)
nested-ternary repro Ok(None)
5,000 / 100,000 / 1,000,000 nested parens Ok(Some(1.0))

The million-paren case is a 2 MB expression, 30× MAX_SCRIPT_LEN. Nothing overflowed.

The recursion arrives with the eval_tokens / find_ternary_split evaluator (PR #95), which re-enters once per ?. The bound is correct and stays — it is simply pre-emptive, landing ahead of that evaluator rather than behind a live defect. The three comments now say that.

Worth doing rather than leaving: this repo has already had to spend a commit correcting one overclaim (64d0d55, "the path-traversal finding was a stale-binary false alarm"). A comment in shipped source that names a process-kill which never existed is the same mistake in a more durable place.

The bound landed in #115 with three comments asserting that this evaluator is
recursive and can be made to abort the process. It is not, and it cannot. The
commit message was corrected before that PR merged; the source comments were
not, so main currently documents a crash that no released version had.

What is actually there: `eval_script_expr` is `tokenize_script` ->
`shunting_yard` -> `evaluate_rpn`, three flat loops over a `Vec`, and `?` is
not a token at all (`tokenize_script` returns `None` on it). Measured with the
bound removed on a 2 MiB stack: the 80,001-byte / 20,000-ternary source returns
`None`, and a 1,000,000-deep parenthesised expression returns `Some(1.0)`.
Nothing overflows.

The recursion arrives with the `eval_tokens` / `find_ternary_split` evaluator,
which re-enters once per `?`. The bound is real and worth keeping; it is simply
pre-emptive, landing ahead of that evaluator rather than behind a live defect.
The comments now say so.

No functional change. Only doc comments move.
@xerj-org
xerj-org merged commit 7ba79ab into main Aug 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant