[ 
https://issues.apache.org/jira/browse/SSHD-1287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576404#comment-17576404
 ] 

Thomas Wolf commented on SSHD-1287:
-----------------------------------

SSH packet sizes and SFTP buffer sizes are not directly related. If you 
transferred a large file, you'd see that multiple SSH packets are sent and 
received for a SFTP buffer that is larger than the receiver's SSH packet size.

But admittedly there are a number of problems in this area:
 * {{AbstractSftpClient}} by default uses indeed buffer sizes that match packet 
sizes. The logic there is a bit broken, though; I would have expected it to use 
the remote window's packet size or a multiple thereof (minus a few bytes for 
protocol overhead) for writing, and the local window's packet size (or a 
multiple, again minus protocol overhead) for reading. It doesn't.
 * The server has a (configurable) limit for the maximum read request size. If 
more is requested, it returns only at most that limit bytes. The limit is by 
default 63kB.
 * This leads to strange behavior when a client uses a larger buffer, for 
instance via {{SftpClient.read(path, bufferSize)}}. For instance with buffer 
size 100kB, a 1000kB file, and a window size of 2MB, Apache MINA sshd first 
sends 10 read requests to read 100kB at offsets 0, 100kB, 200kB, 300kB, and so 
on. It then gets replies from the server for 63kB at offsets 0, 100kB, etc. It 
handles these replies in order, so first the 63kB at offset 0. When it wants to 
handle the 63kB at offset 100kB, it notices that 37kB are missing, and requests 
them at offset 63kB synchronously, writes them, and only then deals with the 
63kB at offset 100kB. The same then repeats for all other requests, since 
they're all short.
 * If a bufferSize > 126kB (twice the server's read size limit) is used, 
{{SftpInputStreamAsync}} has a bug that overwrites data during this synchronous 
re-load of missing data, so the file is corrupted in the transfer.

Finally note that OpenSSH uses the {{[email protected]}} SFTP extension to let 
the client choose appropriate buffer sizes for uploading or downloading files 
based on what the server supports.

> Use the maximum packet size of the communication partner
> --------------------------------------------------------
>
>                 Key: SSHD-1287
>                 URL: https://issues.apache.org/jira/browse/SSHD-1287
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 2.8.0
>            Reporter: Ryosuke Kanda
>            Priority: Minor
>         Attachments: ClientMain.java, ConsoleLog, ServerMain.java
>
>
> It appears that SSHD may use the maximum packet size presented by the 
> communicating party to request reception.
> RFC 4254 contains the following statement, where "maximum packet size" can be 
> read as "the maximum packet size that the sender is willing to accept" (as in 
> "initial window size").
> {code:java}
> Section 5.1 Opening a Channel
> The 'maximum packet size' specifies the maximum size of 
> 2an individual data packet that can be sent to the sender.{code}
> The client/server must comply with its own declared maximum packet size.
>  
> I encountered this issue when I was using "freeSSHd" as an SFTP server.
> The version of freeSSHd is 1.3.1.
> The event is confirmed by creating a server with SSHD.
> Attached are the client and server sources, as well as the client debug logs 
> (up to the first read request).
> When communicating with these, the client knows that its maximum packet size 
> is "32768" and the server's maximum packet size is "65536".
> {code:java}
> // client window
> [main] DEBUG org.apache.sshd.common.channel.Window - 
> init(Window[client/local](SftpChannelSubsystem[id=0, 
> recipient=-1]-ClientSessionImpl[user@localhost/127.0.0.1:10022][sftp])) 
> size=2097152, max=2097152, packet=32768
> // server window
> [sshd-SshClient[5702b3b1]-nio2-thread-3] DEBUG 
> org.apache.sshd.common.channel.Window - 
> init(Window[client/remote](SftpChannelSubsystem[id=0, 
> recipient=0]-ClientSessionImpl[user@localhost/127.0.0.1:10022][sftp])) 
> size=2097152, max=2097152, packet=65536 {code}
> And when requesting to receive a file, it requests to read 65536 bytes at a 
> time. This means that it attempts to receive packets that exceed 32768 bytes.
> {code:java}
> [main] TRACE org.apache.sshd.sftp.client.impl.SftpInputStreamAsync - 
> sendRequests(SftpInputStreamAsync[ClientSessionImpl[user@localhost/127.0.0.1:10022]][/data4M.txt])
>  enqueue pending ack: SftpAckData[id=103, offset=0, length=65536] {code}
>  
> I hope this report is helpful.
> I am doing machine translation, so please allow it to be unnatural.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to