Skip to content

fix: cap AttrValue nesting depth to prevent stack overflow on deeply nested config - #1216

Draft
gominimal-aw-bot[bot] wants to merge 1 commit into
mainfrom
inbox-patch/decode-attr-depth-cap-3066b1b8af9f1806
Draft

fix: cap AttrValue nesting depth to prevent stack overflow on deeply nested config#1216
gominimal-aw-bot[bot] wants to merge 1 commit into
mainfrom
inbox-patch/decode-attr-depth-cap-3066b1b8af9f1806

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABMrkm-g

Evaluating a layer whose config nests lists, maps, or enum variants ~100+ levels deep aborted the entire process with an uncatchable fatal runtime error: stack overflow. AttrValue::from_term in the decode crate recursed through the List, Map, and EnumVariant cases with no depth limit, and Nickel forces one level of evaluation per recursive call, so deep nesting exhausted the stack before any error could be returned.

This caps attribute-value construction at 128 nesting levels and returns a new structured Error::AttrTooDeep once the cap is exceeded, turning hostile or accidental deep nesting into a recoverable error instead of a crash. A regression test drives evaluation past the cap on a large-stack worker thread and asserts the structured error rather than an abort. (The TOML argument path was also considered but is unaffected: the toml crate enforces its own nesting limit and returns a structured parse error.)

Verification

  • cargo fmt --all --check — clean, no diff
  • cargo clippy --workspace --locked -- -D warnings — exit 0, no warnings
  • cargo build --workspace --locked — exit 0
  • cargo test --workspace --locked — exit 0; decode: 57 passed, 0 failed (incl. nesting_past_cap_errors_instead_of_overflowing)

Note

Cap AttrValue nesting depth at 128 to prevent stack overflow on deeply nested config

Deeply nested Nickel attribute values could cause unbounded recursion in AttrValue::from_term, leading to a stack overflow. A MAX_ATTR_DEPTH constant (128) is introduced in attrs.rs, and recursion is tracked via a new from_term_at helper that returns Err(Error::AttrTooDeep { max_depth: 128 }) when the limit is exceeded. The new error variant is formatted and reported with a human-readable message in error.rs.

Macroscope summarized 97603c1.

Deeply nested config (lists, maps, or enum variants ~100+ levels
deep) aborted the process with an uncatchable stack overflow:
AttrValue::from_term recursed with no depth limit, and evaluation
forces one level of nesting per recursive call.

Cap construction at 128 levels and return a structured
Error::AttrTooDeep past the cap, turning the abort into a
recoverable error. Add a regression test asserting the structured
error rather than an abort.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d12e4e86-1c1f-4747-82cc-b66622867dff

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

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.

0 participants