decoder: raise default max depth to 1500 and add DecodeUnlimitedDepth#32
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Raises the default XDR decoding depth limit in xdr3 from 250 to 1500 and introduces a DecodeUnlimitedDepth sentinel (math.MaxUint) for callers decoding trusted XDR (e.g., stellar-core output) where deep nesting is expected.
Changes:
- Raise
DecodeDefaultMaxDepthfrom 250 to 1500 and expand its doc comment. - Add new
DecodeUnlimitedDepthconstant and document it inDecodeOptions.MaxDepth. - Add
TestDecodeUnlimitedDepthcovering both the default-limit rejection and the unlimited-depth success path via a self-referentiallinkedNodetype.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| xdr3/decode.go | Bumps default max depth to 1500 and adds DecodeUnlimitedDepth sentinel with docs on MaxDepth. |
| xdr3/decode_test.go | Adds linkedNode helper and TestDecodeUnlimitedDepth exercising default-limit failure and unlimited-depth success. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The previous default decoding depth of 250 was too shallow for some legitimately deep XDR. Raise the default to 1500 for untrusted, user-supplied input, and add a DecodeUnlimitedDepth sentinel (math.MaxUint) so callers decoding trusted XDR emitted by stellar-core can disable the limit entirely. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
baf18dc to
a00ebd7
Compare
karthikiyer56
approved these changes
May 29, 2026
tamirms
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
DecodeDefaultMaxDepthfrom 250 → 1500. This is the bound applied to untrusted, user-supplied XDR (anyone usingNewDecoder/UnmarshalorMaxDepth: 0).DecodeUnlimitedDepth = uint(math.MaxUint). Callers decoding trusted XDR (e.g. emitted by stellar-core) can setDecodeOptions{MaxDepth: xdr3.DecodeUnlimitedDepth}to disable the depth limit.Why
The previous default of 250 was too shallow for some legitimately deep XDR. User-supplied input still needs a guard against unbounded recursion / stack growth, so the default is raised to 1500 rather than removed. Trusted core output, which is acyclic and finite but can nest deeply, gets an explicit opt-out.
Usage
Implementation notes
0already means "use the default", so a separate sentinel was needed for "unlimited".math.MaxUintreuses the existing countdown logic untouched — no hot-path change — and is effectively unbounded for any real nesting.DecodeUnlimitedDepthis not truly unbounded; a genuinely cyclic/adversarial input would no longer be caught by the depth check. That's intended, since this knob is only for trusted input (documented on the constant).Testing
TestDecodeUnlimitedDepth: builds a chain nested 100 levels past the default, confirms the default limit rejects it (ErrMaxDecodingDepth) andDecodeUnlimitedDepthdecodes it cleanly.xdr,xdr2,xdr3.🤖 Generated with Claude Code