Skip to content

Fix SkipWhitespace returning early EOF on whitespace-only chunks#2461

Merged
fnando merged 4 commits into
stellar:mainfrom
gabrielrondon:fix/skip-whitespace-eof
Apr 20, 2026
Merged

Fix SkipWhitespace returning early EOF on whitespace-only chunks#2461
fnando merged 4 commits into
stellar:mainfrom
gabrielrondon:fix/skip-whitespace-eof

Conversation

@gabrielrondon
Copy link
Copy Markdown
Contributor

What

Fix SkipWhitespace::read() signaling EOF when a read chunk contains only whitespace bytes. Add unit tests for the reader.

Why

When base64 XDR input contains whitespace (e.g., newlines from terminal paste or multiline file), read() returns Ok(0) for whitespace-only chunks. The Read trait interprets Ok(0) as EOF, causing silent truncation and subsequent XDR decode errors.

The fix loops until at least one non-whitespace byte is found or the inner reader returns true EOF.

Affects all commands using tx_envelope_from_input(): tx hash, tx sign, tx send, tx simulate, tx op add.

Known limitations

The upstream stellar-xdr crate has the same bug in its own SkipWhitespace (used by tx decode). This PR only fixes the stellar-cli copy. The upstream fix should be tracked separately in stellar/rs-stellar-xdr.

Closes #2431

When a read() call returns a buffer containing only whitespace bytes,
SkipWhitespace returns Ok(0) which the Read trait interprets as EOF.
This causes silent truncation of base64 input containing whitespace
(e.g., newlines from terminal paste or file formatting).

Fix by looping until at least one non-whitespace byte is found or the
inner reader returns true EOF.

Closes stellar#2431
Copilot AI review requested due to automatic review settings March 23, 2026 23:36
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes SkipWhitespace::read() in the tx XDR input path so it won’t incorrectly signal EOF (Ok(0)) when a read chunk contains only whitespace, preventing silent truncation of base64-encoded XDR read from stdin/args.

Changes:

  • Update SkipWhitespace<R>::read() to keep reading until it produces at least one non-whitespace byte or the inner reader reaches true EOF.
  • Add unit tests for SkipWhitespace behavior.

Comment thread cmd/soroban-cli/src/commands/tx/xdr.rs
@gabrielrondon
Copy link
Copy Markdown
Contributor Author

Hi — friendly ping on this one. CI is green after the reorder fix on Apr 3. Happy to address any feedback.

@fnando fnando enabled auto-merge (squash) April 20, 2026 20:02
Copy link
Copy Markdown
Member

@fnando fnando left a comment

Choose a reason for hiding this comment

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

lgtm

@fnando fnando merged commit a3b7bf7 into stellar:main Apr 20, 2026
208 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Apr 20, 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.

xdr decode commands fails with XDR decode error when base64 input contains whitespace

3 participants