Library callers on small threads can still overflow before MAX_SOURCE_NESTING_DEPTH is reached in debug builds

Open
#301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend, testing

Research direction

Read PR #278’s design discussion and the measurements from #277, then inspect the parser entry points amblicit_syntax::parse_module and amblicit::check, plus crates/amblicit-syntax/tests/parse_nesting.rs and the syntax README requirement SYNTAX-REQ-018. Start by reproducing the debug overflow on a 2 MiB thread; done means the committed test parses parentheses and unary sources to MAX_SOURCE_NESTING_DEPTH - 2 without aborting and the README requirement matches the resulting behavior.

Written by the indexing model from the issue text.

Description

bug

Summary

PR #278 bounds the parser's recursion at MAX_SOURCE_NESTING_DEPTH (256) and makes the amblicit binary run each request on a 64 MiB thread, so the limit holds for the CLI on every platform's default main thread.

The limit bounds recursion, not the thread. Each parser level costs stack according to the build profile (about 4.3 KiB in release, several times that in debug, measured in #277: debug overflowed at 386 parentheses on an 8 MiB main thread). A library caller of amblicit_syntax::parse_module / amblicit::check that parses untrusted sources on a small thread (for example Rust's default 2 MiB spawned thread in a debug build) can therefore still overflow before the parser reaches the limit. The PR's own unit witnesses run on a 64 MiB thread for this reason (crates/amblicit-syntax/tests/parse_nesting.rs, WITNESS_STACK_BYTES).

#277 asked for the library entry point to be safe on smaller thread stacks as well; #278 documents the requirement on the caller (syntax README, SYNTAX-REQ-018) instead of meeting it.

Options

  • Reduce the parser's per-level stack cost (smaller frames, fewer nested helper closures on the hot path) so 256 levels fit a 2 MiB thread in debug, and add a witness that parses to the limit on a 2 MiB thread in both profiles.
  • Or make the library entry points run the parser on an internally sized thread, as the binary does, accepting a thread spawn per call.
  • Or lower the limit, accepting that fewer legitimate sources parse.

Acceptance

  • A committed test parses a source at MAX_SOURCE_NESTING_DEPTH - 2 on a 2 MiB thread in a debug build without aborting, for the parentheses and unary shapes at least.
  • The syntax README's caller requirement is removed or narrowed to match.

Deferred from #278; see its design discussion for the measurements.

Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flyingrobots/edict

All issues in flyingrobots/edict

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.