You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2004/11/24 20:23:25 UTC

cvs commit: jakarta-commons/codec/src/test/org/apache/commons/codec/binary Base64Test.java

ggregory    2004/11/24 11:23:25

  Modified:    codec/src/java/org/apache/commons/codec/binary Base64.java
               codec/src/test/org/apache/commons/codec/binary
                        Base64Test.java
  Log:
  ASF Bugzilla Bug 30825
  [codec] Under some circumstances Base64.isArrayByteBase64() throws a ArrayIndexOutOfBoundsException.
  http://issues.apache.org/bugzilla/show_bug.cgi?id=30825
  
  Revision  Changes    Path
  1.23      +8 -2      jakarta-commons/codec/src/java/org/apache/commons/codec/binary/Base64.java
  
  Index: Base64.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/binary/Base64.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Base64.java	30 Oct 2004 00:18:57 -0000	1.22
  +++ Base64.java	24 Nov 2004 19:23:25 -0000	1.23
  @@ -153,10 +153,16 @@
           lookUpBase64Alphabet[63] = (byte) '/';
       }
   
  +    /**
  +     * Returns whether or not the <code>octect</code> is in the base 64 alphabet.
  +     * 
  +     * @param octect The value to test
  +     * @return <code>true</code> if the value is defined in the the base 64 alphabet, <code>false</code> otherwise.
  +     */
       private static boolean isBase64(byte octect) {
           if (octect == PAD) {
               return true;
  -        } else if (base64Alphabet[octect] == -1) {
  +        } else if (octect < 0 || base64Alphabet[octect] == -1) {
               return false;
           } else {
               return true;
  
  
  
  1.16      +12 -1     jakarta-commons/codec/src/test/org/apache/commons/codec/binary/Base64Test.java
  
  Index: Base64Test.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/test/org/apache/commons/codec/binary/Base64Test.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Base64Test.java	19 Apr 2004 01:14:29 -0000	1.15
  +++ Base64Test.java	24 Nov 2004 19:23:25 -0000	1.16
  @@ -513,6 +513,17 @@
   		assertEquals("The quick brown fox jumped over the lazy dogs.",new String(Base64.decodeBase64("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
   	}
   
  +    public void testIsArrayByteBase64() {        
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {Byte.MIN_VALUE}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {-125}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {-10}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {0}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {64, Byte.MAX_VALUE}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {Byte.MAX_VALUE}));
  +        assertTrue(Base64.isArrayByteBase64(new byte[] {'A'}));
  +        assertFalse(Base64.isArrayByteBase64(new byte[] {'A', Byte.MIN_VALUE}));
  +    }
  +
       public void testObjectDecodeWithInvalidParameter() throws Exception {
           boolean exceptionThrown = false;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org