Skip to content

id(tuple): cap nested tuple decode depth at 64 - #4083

Merged
dezren39 merged 1 commit into
mainfrom
queue/5100-2121-tuple-decode-limit
Nov 2, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/5100-2121-tuple-decode-limit

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #2121

tuple::decode recursed on every NESTED tag with no depth limit. The decoder is reached for peer-written iroh-docs entry keys (tag alpha/omega keys), so a crafted ~100 KB key with ~50k nested tags aborted the process with a stack overflow instead of returning an error.

Change (pkgs/id/crates/id-core/src/tuple.rs — the module moved here in the id-core crate split; the unbounded recursion was identical)

  • Add named pub const MAX_TUPLE_NESTING_DEPTH: usize = 64, matching the peer-CBOR RECURSION_LIMIT = 64 in chain.rs.
  • Thread the current depth through decode_one; a nested element beyond the cap returns an ordinary anyhow error before recursing further. Alpha/omega tag-key decoders get this automatically since they call tuple::decode.
  • Document the cap and the existing encoder asymmetry: TupleEncoder stays infallible and can encode deeper than decode accepts — no breaking change to its public signature in this fix.

Tests (new, in-module)

  • test_decode_at_nesting_limit_roundtrips — exactly 64 nested tuples decode and walk down to the innermost value.
  • test_decode_one_over_nesting_limit_errors — 65 nested tuples return Err.
  • test_decode_hostile_depth_errors_on_small_stack — 50k NESTED bytes decode on a 2 MiB-stack thread and return Err instead of aborting.

Existing tuple/tag tests run in CI on this PR (CI-first verification; no local build run — laptop load was >50 during this shift and local fleet builds are banned by policy in favour of Actions).

Queue: task 5100 (repo-health-code-pilot), lane F.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 23:58
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27b4fea7-4ddb-4206-99bf-1d85784f5fb6
Commits

Reviewing files that changed from the base of the PR and between 74a872a and a538f12.

Files selected for processing: 1
  • pkgs/id/crates/id-core/src/tuple.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T06:46:57.531168Z a538f12 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · parked

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

@codex review — resuming task 5100; no Codex review on head a538f12 yet. Note: the broad basic-tier failures on this head are Magic Nix Cache throttling (HTTP 418 / ResourceExhausted in job logs), not the change; guard + native arm64 are SUCCESS.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: a538f128a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dezren39
dezren39 merged commit bbc1662 into main Nov 2, 2026
15 of 33 checks passed
@dezren39
dezren39 deleted the queue/5100-2121-tuple-decode-limit branch November 2, 2026 06:47
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.

id(tuple): decode recurses on NESTED with no depth limit — a crafted 100 KB tag key (50k nested tags) aborts the process with a stack overflow

1 participant