Skip to content

Commit

Permalink
Base32 constructor makes a defensive copy of the line separator
Browse files Browse the repository at this point in the history
array
  • Loading branch information
garydgregory committed Apr 20, 2024
1 parent ebe805a commit fcc70e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Optimize memory allocation in PhoneticEngine.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">BCodec and QCodec encode() methods throw UnsupportedCharsetException instead of EncoderException.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Set Javadoc link to latest Java API LTS version.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base32 constructor makes a defensive copy of the line separator array.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 constructor makes a defensive copy of the line separator array.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 constructor makes a defensive copy of a custom alphabet array.</action>
<!-- ADD -->
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/apache/commons/codec/binary/Base32.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,14 @@ private Base32(final int lineLength, final byte[] lineSeparator, final byte[] en
if (lineSeparator == null) {
throw new IllegalArgumentException("lineLength " + lineLength + " > 0, but lineSeparator is null");
}
final byte[] lineSeparatorCopy = lineSeparator.clone();
// Must be done after initializing the tables
if (containsAlphabetOrPad(lineSeparator)) {
final String sep = StringUtils.newStringUtf8(lineSeparator);
if (containsAlphabetOrPad(lineSeparatorCopy)) {
final String sep = StringUtils.newStringUtf8(lineSeparatorCopy);
throw new IllegalArgumentException("lineSeparator must not contain Base32 characters: [" + sep + "]");
}
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;
this.lineSeparator = lineSeparator.clone();
this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparatorCopy.length;
this.lineSeparator = lineSeparatorCopy;
} else {
this.encodeSize = BYTES_PER_ENCODED_BLOCK;
this.lineSeparator = null;
Expand Down

0 comments on commit fcc70e6

Please sign in to comment.