Skip to content

Add depth limit to xdr encoding and decoding - #2675

Merged
mootz12 merged 1 commit into
mainfrom
limit-xdr-depth
Aug 10, 2026
Merged

Add depth limit to xdr encoding and decoding#2675
mootz12 merged 1 commit into
mainfrom
limit-xdr-depth

Conversation

@mootz12

@mootz12 mootz12 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What

Adds a depth limit to all XDR encoding and decoding sites.

Why

This also prevents stack overflow crashes if intentionally deep XDR structs are encountered.

Known limitations

None

@mootz12
mootz12 requested review from fnando and a balanced review from Copilot August 7, 2026 20:00
@mootz12
mootz12 requested a review from a team as a code owner August 7, 2026 20:00
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a 500-level depth limit to XDR encoding and decoding to prevent stack-overflow crashes.

Changes:

  • Replaces unlimited XDR operations across CLI commands.
  • Applies matching limits to supporting crates.
  • Updates related test fixture encoding.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
cmd/soroban-cli/src/utils.rs Defines the shared limit and applies it to utility XDR operations.
cmd/soroban-cli/src/signer/mod.rs Limits signer XDR encoding.
cmd/soroban-cli/src/log/event.rs Limits diagnostic-event encoding.
cmd/soroban-cli/src/key.rs Limits key XDR decoding.
cmd/soroban-cli/src/config/data.rs Limits cached-data encoding.
cmd/soroban-cli/src/commands/tx/xdr.rs Limits transaction input decoding.
cmd/soroban-cli/src/commands/tx/update/sequence_number/next.rs Limits updated transaction output.
cmd/soroban-cli/src/commands/tx/simulate.rs Limits simulated transaction output.
cmd/soroban-cli/src/commands/tx/sign.rs Limits signed transaction output.
cmd/soroban-cli/src/commands/tx/op/add/mod.rs Limits operation transaction output.
cmd/soroban-cli/src/commands/tx/fetch/result.rs Limits fetched result encoding.
cmd/soroban-cli/src/commands/tx/fetch/meta.rs Limits fetched metadata encoding.
cmd/soroban-cli/src/commands/tx/fetch/envelope.rs Limits fetched envelope encoding.
cmd/soroban-cli/src/commands/tx/edit.rs Limits transaction JSON/XDR conversion.
cmd/soroban-cli/src/commands/tx/args.rs Limits transaction output encoding.
cmd/soroban-cli/src/commands/snapshot/create.rs Limits archive XDR decoding.
cmd/soroban-cli/src/commands/network/settings.rs Limits settings XDR output.
cmd/soroban-cli/src/commands/ledger/entry/fetch/contract_data.rs Limits contract-key decoding.
cmd/soroban-cli/src/commands/events.rs Limits event value and topic decoding.
cmd/soroban-cli/src/commands/contract/upload.rs Limits upload-related XDR operations.
cmd/soroban-cli/src/commands/contract/restore.rs Limits restore transaction output.
cmd/soroban-cli/src/commands/contract/read.rs Limits contract-data output encoding.
cmd/soroban-cli/src/commands/contract/invoke.rs Limits invoke transaction output.
cmd/soroban-cli/src/commands/contract/id/wasm.rs Limits contract-ID preimage encoding.
cmd/soroban-cli/src/commands/contract/extend.rs Limits extend transaction output.
cmd/soroban-cli/src/commands/contract/deploy/wasm.rs Limits WASM deployment output.
cmd/soroban-cli/src/commands/contract/deploy/asset.rs Limits asset deployment output.
cmd/soroban-cli/src/commands/contract/build.rs Limits contract metadata and specification encoding.
cmd/soroban-cli/src/assembled.rs Limits simulation and assembly XDR operations.
cmd/crates/stellar-ledger/src/lib.rs Limits Ledger signing payload encoding.
cmd/crates/soroban-spec-typescript/src/lib.rs Limits TypeScript specification encoding.
cmd/crates/soroban-spec-tools/src/contract.rs Limits specification JSON encoding.

Comment thread cmd/soroban-cli/src/commands/tx/fetch/result.rs
Comment thread cmd/soroban-cli/src/commands/tx/fetch/meta.rs
Comment thread cmd/soroban-cli/src/commands/tx/fetch/envelope.rs
Comment thread cmd/soroban-cli/src/log/event.rs
Comment thread cmd/crates/soroban-spec-typescript/src/lib.rs
Comment thread cmd/soroban-cli/src/commands/tx/xdr.rs

@leighmcculloch leighmcculloch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, and also relatively low risk making this change in the cli since if a problem does arise where we have set it too low then we can quickly ship a new release and the release channels are all very accessible.

See inline comments as there are some places that I think we won't see the intended affect because the rpc client crate already decodes them without a depth limit (iirc we have not added depth limits there).

Something else I wonder about is will the depth limit actually prevent stack overflow in some of the cases like claimable balances. But in any case this is an improvement.

Comment thread cmd/soroban-cli/src/log/event.rs
Comment thread cmd/soroban-cli/src/commands/tx/fetch/meta.rs
Comment thread cmd/soroban-cli/src/commands/tx/fetch/envelope.rs
Comment thread cmd/soroban-cli/src/commands/tx/fetch/result.rs
@mootz12
mootz12 merged commit 965aa47 into main Aug 10, 2026
230 checks passed
@mootz12
mootz12 deleted the limit-xdr-depth branch August 10, 2026 13:05
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants