Fix SkipWhitespace returning early EOF on whitespace-only chunks#2461
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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
SkipWhitespacebehavior.
Contributor
Author
|
Hi — friendly ping on this one. CI is green after the reorder fix on Apr 3. Happy to address any feedback. |
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
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()returnsOk(0)for whitespace-only chunks. TheReadtrait interpretsOk(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-xdrcrate has the same bug in its ownSkipWhitespace(used bytx decode). This PR only fixes thestellar-clicopy. The upstream fix should be tracked separately instellar/rs-stellar-xdr.Closes #2431