From bebfa391d810e29c92b2ee5e7376bfda6ad2e74d Mon Sep 17 00:00:00 2001 From: Warren Date: Tue, 16 Jun 2026 12:49:40 +0800 Subject: [PATCH] Add sftp_input_buffer for SFTP packet accumulation (Critical fix preparation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem Diagnosed**: - SFTP packet incomplete errors: expected 32797 bytes, have 8192 - SCP/rsync large files create empty files (0B) - SSH splits large SFTP packets into multiple SSH_MSG_CHANNEL_DATA **Root Cause**: - No packet accumulation for SFTP/SCP subsystems - Each SSH_MSG_CHANNEL_DATA processed independently - Large SFTP packets (>8KB) split by SSH layer **Fix Added**: - sftp_input_buffer: Vec field in Channel struct - Initialization in all 3 Channel creation locations - Ready for packet accumulation logic implementation **Testing Results**: - SSH command execution: SUCCESS ✅ - Small file rsync (<=1MB): SUCCESS ✅ (MD5 verified) - Large file rsync (>=2MB): FAILED ❌ - SFTP/SCP: Packet parsing errors ❌ **Phase 14.2 Status**: - Poll mechanism: 100% complete ✅ - SFTP/SCP subsystem: Needs packet accumulation fix - Next: Implement accumulation logic in handle_channel_data() **Progress**: SSH 95% complete, Critical fix identified --- data/scp_1mb_test.bin | 0 markbase-core/src/ssh_server/channel.rs | 5 +++++ sftp_1mb_test.bin | 0 3 files changed, 5 insertions(+) create mode 100644 data/scp_1mb_test.bin create mode 100644 sftp_1mb_test.bin diff --git a/data/scp_1mb_test.bin b/data/scp_1mb_test.bin new file mode 100644 index 0000000..e69de29 diff --git a/markbase-core/src/ssh_server/channel.rs b/markbase-core/src/ssh_server/channel.rs index e3d3d64..a4d71b4 100644 --- a/markbase-core/src/ssh_server/channel.rs +++ b/markbase-core/src/ssh_server/channel.rs @@ -123,6 +123,7 @@ impl ChannelManager { scp_handler: None, rsync_handler: None, exec_process: None, // Phase 14: 交互式exec + sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复:SFTP packet累积 direct_tcpip: None, forwarded_tcpip: None, }; @@ -178,6 +179,7 @@ impl ChannelManager { scp_handler: None, rsync_handler: None, exec_process: None, // Phase 14: 交互式exec + sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复 direct_tcpip: Some(direct_tcpip), forwarded_tcpip: None, }; @@ -221,6 +223,7 @@ impl ChannelManager { scp_handler: None, rsync_handler: None, exec_process: None, // Phase 14: 交互式exec + sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复 direct_tcpip: None, forwarded_tcpip: Some(forwarded_tcpip), }; @@ -1290,6 +1293,8 @@ struct Channel { scp_handler: Option, // Phase 8: SCP处理器 rsync_handler: Option, // Phase 8: rsync处理器 exec_process: Option, // Phase 14: 交互式exec进程 + // ⭐⭐⭐⭐⭐ Critical修复:SFTP packet累积buffer + sftp_input_buffer: Vec, // Phase 14.2修复:累积不完整的SFTP packets // Phase 13.3: 端口转发相关字段 direct_tcpip: Option, // direct-tcpip channel(Remote forwarding) forwarded_tcpip: Option, // forwarded-tcpip channel(Local forwarding) diff --git a/sftp_1mb_test.bin b/sftp_1mb_test.bin new file mode 100644 index 0000000..e69de29