feixiangff commented on issue #86: [bugfix] fix transfer large file bug(more 
than1GB)
URL: https://github.com/apache/mina-sshd/pull/86#issuecomment-454300939
 
 
   > I haven't looked at the compact question, but the `getNextPowerOf2` should 
be fixed anyway. I suggest the following:
   > 
   > ```
   > diff --git 
a/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java 
b/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
   > index 113e74e0..7c71a3dd 100644
   > --- 
a/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
   > +++ 
b/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
   > @@ -60,7 +60,7 @@ public final class NumberUtils {
   >  
   >      public static long getNextPowerOf2(long value) {
   >          long j = 1L;
   > -        while (j < value) {
   > +        while (j < value && j > 0) {
   >              j <<= 1;
   >          }
   >          return j;
   > @@ -68,7 +68,7 @@ public final class NumberUtils {
   >  
   >      public static int getNextPowerOf2(int value) {
   >          int j = 1;
   > -        while (j < value) {
   > +        while (j < value && j > 0) {
   >              j <<= 1;
   >          }
   >          return j;
   > diff --git 
a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java 
b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
   > index 7fff5d0c..31387db4 100644
   > --- 
a/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
   > +++ 
b/sshd-common/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
   > @@ -518,7 +518,11 @@ public final class BufferUtils {
   >  
   >      public static int getNextPowerOf2(int value) {
   >          // for 0-7 return 8
   > -        return (value < Byte.SIZE) ? Byte.SIZE : 
NumberUtils.getNextPowerOf2(value);
   > +        return (value < Byte.SIZE)
   > +                ? Byte.SIZE
   > +                : (value > (1 << 30))
   > +                    ? value
   > +                    : NumberUtils.getNextPowerOf2(value);
   >      }
   >  
   >      /**
   > diff --git 
a/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java 
b/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
   > index d7c2d320..9ec0937f 100644
   > --- 
a/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
   > +++ 
b/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
   > @@ -19,6 +19,7 @@
   >  
   >  package org.apache.sshd.common.util;
   >  
   > +import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
   >  import org.apache.sshd.util.test.JUnitTestSupport;
   >  import org.apache.sshd.util.test.NoIoTestCase;
   >  import org.junit.FixMethodOrder;
   > @@ -60,6 +61,11 @@ public class NumberUtilsTest extends JUnitTestSupport {
   >          }
   >      }
   >  
   > +    @Test
   > +    public void testNextPowerOf2Max() {
   > +        assertTrue(NumberUtils.getNextPowerOf2(1073741872) < 0);
   > +    }
   > +
   >      @Test
   >      public void testToInteger() {
   >          assertNull("Unexpected null value", NumberUtils.toInteger(null));
   > ```
   
   Yes, but in my case, although the bug in  `getNextPowerOf2` has been fixed, 
I can only transfer the file less than 2GB by SCP, because of the limit of 
return type of getNextPowerOf2(int)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to