Skip to content

Commit 3e0d13c

Browse files
committed
open for different alphabets - check for encodeTable length
1 parent 8b29c52 commit 3e0d13c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ public Base64(final int lineLength, final byte[] lineSeparator, byte[] encodeTab
310310
if (encodeTable == STANDARD_ENCODE_TABLE || encodeTable == URL_SAFE_ENCODE_TABLE) {
311311
decodeTable = DEFAULT_DECODE_TABLE;
312312
} else {
313+
if (encodeTable.length != 64) {
314+
throw new IllegalArgumentException("encodeTable must be exactly 64 bytes long");
315+
}
313316
decodeTable = calculateDecodeTable(encodeTable);
314317
}
315318

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ public void testBase64() {
116116
assertEquals("decode hello world", "Hello World", decodeString);
117117
}
118118

119+
@Test(expected = IllegalArgumentException.class)
120+
public void testCustomEncodingAlphabet_illegal() {
121+
byte[] encodeTable = {
122+
'.', '-', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'
123+
};
124+
Base64 b64customEncoding = new Base64(encodeTable);
125+
}
126+
119127
@Test
120128
public void testCustomEncodingAlphabet() {
121129
// created a duplicate of STANDARD_ENCODE_TABLE and replaced two chars with

0 commit comments

Comments
 (0)