harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r594188 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/asn1/BerInputStream.java test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java
Date Mon, 12 Nov 2007 15:40:09 GMT
Author: smishura
Date: Mon Nov 12 07:40:07 2007
New Revision: 594188

URL: http://svn.apache.org/viewvc?rev=594188&view=rev
Log:
Fix and regression test for internal buffer reallocation in BerInputStream(InputStream in,
int initialSize)

see HARMONY-5054:
[classlib][security] ASN.1: BerInputStream will incorrectly resize buffer when the enveloped
InputStream has lots of bytes

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java?rev=594188&r1=594187&r2=594188&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java
Mon Nov 12 07:40:07 2007
@@ -25,7 +25,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Calendar;
 
 import org.apache.harmony.security.internal.nls.Messages;
 
@@ -132,8 +131,8 @@
         if (length != INDEFINIT_LENGTH) {
             // input stream has definite length encoding
             // check allocated length to avoid further reallocations
-            if (buffer.length < length) {
-                byte[] newBuffer = new byte[length];
+            if (buffer.length < (length + offset)) {
+                byte[] newBuffer = new byte[length + offset];
                 System.arraycopy(buffer, 0, newBuffer, 0, offset);
                 buffer = newBuffer;
             }

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java?rev=594188&r1=594187&r2=594188&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java
Mon Nov 12 07:40:07 2007
@@ -28,6 +28,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.security.asn1.ASN1Constants;
 import org.apache.harmony.security.asn1.ASN1Exception;
 import org.apache.harmony.security.asn1.BerInputStream;
 
@@ -102,8 +103,29 @@
         } catch (ASN1Exception e) {
             assertTrue(e.getMessage().startsWith("Too long"));
         }
+
+        //
+        // Test for correct internal array reallocation
+        // Regression for HARMONY-5054
+        //
+
+        // must be greater then buffer initial size (16K)
+        int arrayLength = 17000;
+
+        // 1 byte for tag and 3 for length
+        byte[] encoding = new byte[arrayLength + 4];
+
+        // fill tag and length bytes
+        encoding[0] = ASN1Constants.TAG_OCTETSTRING;
+        encoding[1] = (byte) 0x82; // length is encoded in two bytes
+        encoding[2] = (byte) (arrayLength >> 8);
+        encoding[3] = (byte) (arrayLength & 0xFF);
+
+        BerInputStream in = new BerInputStream(new ByteArrayInputStream(
+                encoding));
+        assertEquals(encoding.length, in.getBuffer().length);
     }
-    
+
     /**
      * @tests org.apache.harmony.security.asn1.BerInputStream#BerInputStream(byte[],
      *        int,int)
@@ -146,4 +168,4 @@
             assertEquals("Wrong content length", e.getMessage());
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message