[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mina-commits
Subject:    [mina-sshd] branch master updated: [SSHD-1071] Fix problem when using 64k buffers in SFTP (#168)
From:       gnodet () apache ! org
Date:       2020-09-17 14:44:54
Message-ID: 160035389477.32247.9972251905116711193 () gitbox ! apache ! org
[Download RAW message or body]

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e84b0b  [SSHD-1071] Fix problem when using 64k buffers in SFTP (#168)
8e84b0b is described below

commit 8e84b0bf5f53cad20941bf3127141324b5603352
Author: Guillaume Nodet <gnodet@gmail.com>
AuthorDate: Thu Sep 17 16:44:47 2020 +0200

    [SSHD-1071] Fix problem when using 64k buffers in SFTP (#168)
---
 .../sshd/sftp/client/impl/DefaultSftpClient.java       | 18 ------------------
 .../sshd/sftp/client/impl/SftpOutputStreamAsync.java   |  6 +++---
 .../org/apache/sshd/sftp/client/SftpTransferTest.java  | 15 +++++++++++++--
 3 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java \
b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java \
                index 92d9d09..9db3731 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/DefaultSftpClient.java
@@ -566,24 +566,6 @@ public class DefaultSftpClient extends AbstractSftpClient {
                     }
                     return super.doCloseGracefully();
                 }
-
-                @Override
-                protected Buffer createSendBuffer(Buffer buffer, Channel channel, \
                long length) {
-                    if ((buffer.rpos() >= 9) && (length == buffer.available())) {
-                        int rpos = buffer.rpos();
-                        int wpos = buffer.wpos();
-                        buffer.rpos(rpos - 9);
-                        buffer.wpos(rpos - 8);
-                        buffer.putInt(channel.getRecipient());
-                        buffer.putInt(length);
-                        buffer.wpos(wpos);
-                        Buffer buf = new ByteArrayBuffer(buffer.array(), \
                buffer.rpos(), buffer.available());
-                        buffer.rpos(buffer.wpos());
-                        return buf;
-                    } else {
-                        return super.createSendBuffer(buffer, channel, length);
-                    }
-                }
             };
         }
 
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java \
b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java \
                index dcdac29..7028fe7 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java
                
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpOutputStreamAsync.java
 @@ -127,14 +127,14 @@ public class SftpOutputStreamAsync extends \
OutputStreamWithChannel {  }
 
             int max = bufferSize - (9 + 16 + id.length + 72);
-            int nb = Math.min(len, max - (buffer.wpos() - buffer.rpos()));
+            int nb = Math.min(len, Math.max(0, max - buffer.available()));
             buffer.putRawBytes(b, off, nb);
 
             off += nb;
             len -= nb;
             writtenCount += nb;
 
-            if (buffer.available() == max) {
+            if (buffer.available() >= max) {
                 if (traceEnabled) {
                     log.trace("write({}) flush after {}/{} bytes", this, \
writtenCount, totalLen);  }
@@ -210,7 +210,7 @@ public class SftpOutputStreamAsync extends \
OutputStreamWithChannel {  int reqId = client.send(SftpConstants.SSH_FXP_WRITE, buf);
         SftpAckData ack = new SftpAckData(reqId, offset, avail);
         if (debugEnabled) {
-            log.debug("flush({}) enueue pending ack={}", this, ack);
+            log.debug("flush({}) enqueue pending ack={}", this, ack);
         }
         pendingWrites.add(ack);
 
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTransferTest.java \
b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTransferTest.java index \
                6fcf584..1402071 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTransferTest.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/SftpTransferTest.java
@@ -44,11 +44,18 @@ public class SftpTransferTest extends \
AbstractSftpClientTestSupport {  @Test
     public void testTransferIntegrity() throws IOException {
         for (int i = 0; i < 10; i++) {
-            doTestTransferIntegrity();
+            doTestTransferIntegrity(0);
         }
     }
 
-    protected void doTestTransferIntegrity() throws IOException {
+    @Test
+    public void testTransferIntegrityWithBufferLargerThanPacket() throws IOException \
{ +        for (int i = 0; i < 10; i++) {
+            doTestTransferIntegrity(65536);
+        }
+    }
+
+    protected void doTestTransferIntegrity(int bufferSize) throws IOException {
         Path localRoot = detectTargetFolder().resolve("sftp");
         Files.createDirectories(localRoot);
 
@@ -67,6 +74,10 @@ public class SftpTransferTest extends \
AbstractSftpClientTestSupport {  
         try (ClientSession session = createClientSession();
              SftpFileSystem fs = \
SftpClientFactory.instance().createSftpFileSystem(session)) { +            if \
(bufferSize > 0) { +                fs.setReadBufferSize(bufferSize);
+                fs.setWriteBufferSize(bufferSize);
+            }
 
             Path remoteRoot = fs.getDefaultDir().resolve("target/sftp");
             Path remote0 = remoteRoot.resolve("files-1.txt");


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic