Skip to content

Commit c5291ab

Browse files
committed
CODEC-112 Base64.encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize) throws IAE for valid maxResultSize if isChunked is false
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1063922 13f79535-47bb-0310-9956-ffa450edef68
1 parent b396c53 commit c5291ab

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean
824824
return binaryData;
825825
}
826826

827-
long len = getEncodeLength(binaryData, MIME_CHUNK_SIZE, CHUNK_SEPARATOR);
827+
long len = getEncodeLength(binaryData, isChunked ? MIME_CHUNK_SIZE : 0, CHUNK_SEPARATOR);
828828
if (len > maxResultSize) {
829829
throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
830830
len +

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,19 @@ public void testEncodeOverMaxSize() throws Exception {
336336
testEncodeOverMaxSize(1);
337337
testEncodeOverMaxSize(2);
338338
}
339+
340+
public void testCodec112() { // size calculation assumes always chunked
341+
byte[] in = new byte[] {0};
342+
byte[] out=Base64.encodeBase64(in);
343+
Base64.encodeBase64(in, false, false, out.length);
344+
}
339345

340346
private void testEncodeOverMaxSize(int maxSize) throws Exception {
341347
try {
342348
Base64.encodeBase64(Base64TestData.DECODED, true, false, maxSize);
343349
fail("Expected " + IllegalArgumentException.class.getName());
344350
} catch (IllegalArgumentException e) {
345-
// Expceted
351+
// Expected
346352
}
347353
}
348354

0 commit comments

Comments
 (0)