-
Notifications
You must be signed in to change notification settings - Fork 39
fix: SkipWhitespace must not report EOF on an all-whitespace read #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,35 @@ use std::io::Cursor; | |
| use stellar_xdr::Error; | ||
| use stellar_xdr::{Limited, Limits, ReadXdr, WriteXdr}; | ||
|
|
||
| #[test] | ||
| fn test_skip_whitespace_long_run() -> Result<(), Error> { | ||
| // A whitespace run at least as long as the base64 decoder's internal read | ||
| // buffer (1024 bytes) must not be treated as end-of-input. Before the fix, | ||
| // SkipWhitespace::read returned Ok(0) when a whole delegate read was | ||
| // whitespace, which the decoder interprets as EOF -> silent truncation. | ||
| let v_bytes = [1u32.to_xdr(Limits::none())?, 2u32.to_xdr(Limits::none())?].concat(); | ||
| let core = base64::engine::general_purpose::STANDARD.encode(&v_bytes); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| assert_eq!(core, "AAAAAQAAAAI="); | ||
| let ws = " ".repeat(2048); | ||
|
|
||
| // Leading long whitespace run. | ||
| let leading = format!("{ws}{core}"); | ||
| assert_eq!( | ||
| u64::from_xdr_base64(&leading, Limits::none()), | ||
| Ok((1u64 << 32) | 2u64) | ||
| ); | ||
|
|
||
| // Interior long whitespace run (split the base64 mid-string). | ||
| let (a, b) = core.split_at(4); | ||
| let interior = format!("{a}{ws}{b}"); | ||
| assert_eq!( | ||
| u64::from_xdr_base64(&interior, Limits::none()), | ||
| Ok((1u64 << 32) | 2u64) | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_skip_whitespace() -> Result<(), Error> { | ||
| let v_bytes = [1u32.to_xdr(Limits::none())?, 2u32.to_xdr(Limits::none())?].concat(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point — reworded in 492d03f so the comment no longer pins the base64 crate's private 1024-byte constant; it now just says the run (2048 bytes) is large enough to fill at least one internal read buffer.