@@ -661,7 +661,7 @@ public Base64(final int lineLength, final byte[] lineSeparator, final boolean ur
661661 * 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when
662662 * decoding.
663663 * @param lineSeparator
664- * Each line of encoded data will end with this sequence of bytes.
664+ * Each line of encoded data will end with this sequence of bytes; the constructor makes a defensive copy .
665665 * @param padding padding byte.
666666 * @param encodeTable
667667 * The manual encodeTable - a byte array of 64 chars.
@@ -683,13 +683,14 @@ private Base64(final int lineLength, final byte[] lineSeparator, final byte padd
683683 // TODO could be simplified if there is no requirement to reject invalid line sep when length <=0
684684 // @see test case Base64Test.testConstructors()
685685 if (lineSeparator != null ) {
686- if (containsAlphabetOrPad (lineSeparator )) {
687- final String sep = StringUtils .newStringUtf8 (lineSeparator );
686+ final byte [] lineSeparatorCopy = lineSeparator .clone ();
687+ if (containsAlphabetOrPad (lineSeparatorCopy )) {
688+ final String sep = StringUtils .newStringUtf8 (lineSeparatorCopy );
688689 throw new IllegalArgumentException ("lineSeparator must not contain base64 characters: [" + sep + "]" );
689690 }
690691 if (lineLength > 0 ) { // null line-sep forces no chunking rather than throwing IAE
691- this .encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator .length ;
692- this .lineSeparator = lineSeparator . clone () ;
692+ this .encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparatorCopy .length ;
693+ this .lineSeparator = lineSeparatorCopy ;
693694 } else {
694695 this .encodeSize = BYTES_PER_ENCODED_BLOCK ;
695696 this .lineSeparator = null ;
0 commit comments