Skip to content

Commit fcc70e6

Browse files
committed
Base32 constructor makes a defensive copy of the line separator
array
1 parent ebe805a commit fcc70e6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The <action> type attribute can be add,update,fix,remove.
4949
<action type="fix" dev="ggregory" due-to="Gary Gregory">Optimize memory allocation in PhoneticEngine.</action>
5050
<action type="fix" dev="ggregory" due-to="Gary Gregory">BCodec and QCodec encode() methods throw UnsupportedCharsetException instead of EncoderException.</action>
5151
<action type="fix" dev="ggregory" due-to="Gary Gregory">Set Javadoc link to latest Java API LTS version.</action>
52+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base32 constructor makes a defensive copy of the line separator array.</action>
5253
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 constructor makes a defensive copy of the line separator array.</action>
5354
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 constructor makes a defensive copy of a custom alphabet array.</action>
5455
<!-- ADD -->

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,14 @@ private Base32(final int lineLength, final byte[] lineSeparator, final byte[] en
359359
if (lineSeparator == null) {
360360
throw new IllegalArgumentException("lineLength " + lineLength + " > 0, but lineSeparator is null");
361361
}
362+
final byte[] lineSeparatorCopy = lineSeparator.clone();
362363
// Must be done after initializing the tables
363-
if (containsAlphabetOrPad(lineSeparator)) {
364-
final String sep = StringUtils.newStringUtf8(lineSeparator);
364+
if (containsAlphabetOrPad(lineSeparatorCopy)) {
365+
final String sep = StringUtils.newStringUtf8(lineSeparatorCopy);
365366
throw new IllegalArgumentException("lineSeparator must not contain Base32 characters: [" + sep + "]");
366367
}
367-
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;
368-
this.lineSeparator = lineSeparator.clone();
368+
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparatorCopy.length;
369+
this.lineSeparator = lineSeparatorCopy;
369370
} else {
370371
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
371372
this.lineSeparator = null;

0 commit comments

Comments
 (0)