Skip to content

Commit 3e7120c

Browse files
committed
ASF Bugzilla Bug 30825
[codec] Under some circumstances Base64.isArrayByteBase64() throws a ArrayIndexOutOfBoundsException. http://issues.apache.org/bugzilla/show_bug.cgi?id=30825 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130429 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3f4e926 commit 3e7120c

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
3232
* @author Apache Software Foundation
3333
* @since 1.0-dev
34-
* @version $Id: Base64.java,v 1.22 2004/10/30 00:18:57 ggregory Exp $
34+
* @version $Id: Base64.java,v 1.23 2004/11/24 19:23:25 ggregory Exp $
3535
*/
3636
public class Base64 implements BinaryEncoder, BinaryDecoder {
3737

@@ -153,10 +153,16 @@ public class Base64 implements BinaryEncoder, BinaryDecoder {
153153
lookUpBase64Alphabet[63] = (byte) '/';
154154
}
155155

156+
/**
157+
* Returns whether or not the <code>octect</code> is in the base 64 alphabet.
158+
*
159+
* @param octect The value to test
160+
* @return <code>true</code> if the value is defined in the the base 64 alphabet, <code>false</code> otherwise.
161+
*/
156162
private static boolean isBase64(byte octect) {
157163
if (octect == PAD) {
158164
return true;
159-
} else if (base64Alphabet[octect] == -1) {
165+
} else if (octect < 0 || base64Alphabet[octect] == -1) {
160166
return false;
161167
} else {
162168
return true;

src/test/org/apache/commons/codec/binary/Base64Test.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import junit.framework.TestCase;
2424

2525
/**
26-
* @version $Id: Base64Test.java,v 1.15 2004/04/19 01:14:29 ggregory Exp $
26+
* @version $Id: Base64Test.java,v 1.16 2004/11/24 19:23:25 ggregory Exp $
2727
* @author Apache Software Foundation
2828
*/
2929
public class Base64Test extends TestCase {
@@ -513,6 +513,17 @@ public void testIgnoringNonBase64InDecode() throws Exception {
513513
assertEquals("The quick brown fox jumped over the lazy dogs.",new String(Base64.decodeBase64("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
514514
}
515515

516+
public void testIsArrayByteBase64() {
517+
assertFalse(Base64.isArrayByteBase64(new byte[] {Byte.MIN_VALUE}));
518+
assertFalse(Base64.isArrayByteBase64(new byte[] {-125}));
519+
assertFalse(Base64.isArrayByteBase64(new byte[] {-10}));
520+
assertFalse(Base64.isArrayByteBase64(new byte[] {0}));
521+
assertFalse(Base64.isArrayByteBase64(new byte[] {64, Byte.MAX_VALUE}));
522+
assertFalse(Base64.isArrayByteBase64(new byte[] {Byte.MAX_VALUE}));
523+
assertTrue(Base64.isArrayByteBase64(new byte[] {'A'}));
524+
assertFalse(Base64.isArrayByteBase64(new byte[] {'A', Byte.MIN_VALUE}));
525+
}
526+
516527
public void testObjectDecodeWithInvalidParameter() throws Exception {
517528
boolean exceptionThrown = false;
518529

0 commit comments

Comments
 (0)