fix: negotiate SFTP read limits - #273
Merged
Merged
Conversation
Advertise bssh-server's SFTP limits through limits@openssh.com so bssh clients size pipelined downloads below the server's enforced read cap instead of triggering a short-read failure above 255 KiB. The pipelined client read path now accepts a legal short DATA reply before EOF, writes the partial chunk in order, and reissues the missing byte range so downloads remain correct even when a server chooses a smaller per-read cap. Regression coverage adds in-process bssh-to-bssh SFTP transfers for 300 KiB and multi-megabyte files plus a synthetic server that deliberately returns short reads before EOF. Refs #271
Member
Author
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
Reviewer validation run:
|
Clamp advertised SFTP read and write limits to the negotiated packet payload ceiling before sizing client transfer chunks, so a peer cannot inflate allocations or trigger protocol-length truncation with oversized limits@openssh.com values. Treat an empty DATA packet before a known file size as an unexpected short read instead of completing successfully with truncated output, while still using empty DATA as EOF when no known remaining bytes exist. Validated with cargo fmt --check, cargo clippy --test sftp_limits_download_test -- -D warnings, cargo test --test sftp_limits_download_test, cargo test -p bssh-russh-sftp --lib client::fs::file, and cargo check --lib --tests. Refs #271
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.
Summary
limits@openssh.comextension and by making pipelined reads recover from legal shortDATAreplies before EOF.DATAbefore a known EOF so malicious or buggy peers cannot cause oversized requests, protocol-length truncation, or silently truncated downloads.What changed
src/server/sftp.rsadvertiseslimits@openssh.com=1and answers the extended request with packet, read, write, and open-handle limits derived from the existing server configuration and enforcement constants; unknown extensions remain unsupported.crates/bssh-russh-sftp/src/client/fs/file.rspreserves partial read data, reissues only the missing range, keeps offset-ordered reassembly, clamps negotiated read/write chunks to packet payload ceilings, and rejects zero-length data before the size reported byfstat.crates/bssh-russh-sftp/src/extensions.rsserializesLimitsExtensionwith the existing extension payload machinery.tests/sftp_limits_download_test.rscovers extension advertisement and wire values, 300 KiB and multi-megabyte in-process round trips, deliberate short reads, premature empty data, oversized advertised limits, and read/write packet-bound clamping.ARCHITECTURE.mddocuments SFTP limits negotiation, short-read recovery, and untrusted peer-limit clamping.Changes during review
DATAbefore a known EOF as an integrity error rather than successful truncation, with dedicated regression coverage.Test plan
cargo fmt --checkcargo clippy -- -D warningscargo test --lib(1407 passed,9 ignored)known_hostsentry rejects the machine's current localhost key.cargo test --test sftp_limits_download_testcargo test -p bssh-russh-sftp --lib client::fs::filecargo build --releasebsshto releasebssh-server3 MB upload/download round trip with byte comparison and matching SHA-256; no read-cap warning.bsshto stock OpenSSH SFTP 3 MB upload/download round trip with byte comparison and matching SHA-256.Closes #271