From d2215d5dec3031f819c3bb514587d92a6aec8eff Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 20 Apr 2024 13:46:13 -0400 Subject: [PATCH] Base32 constructor fails-fast with a NullPointerException if the custom alphabet array is null --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/codec/binary/Base32.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 01ee6076e9..c1e7f5e6a4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -49,6 +49,7 @@ The type attribute can be add,update,fix,remove. Optimize memory allocation in PhoneticEngine. BCodec and QCodec encode() methods throw UnsupportedCharsetException instead of EncoderException. Set Javadoc link to latest Java API LTS version. + Base32 constructor fails-fast with a NullPointerException if the custom alphabet array is null. Base32 constructor makes a defensive copy of the line separator array. Base64 constructor makes a defensive copy of the line separator array. Base64 constructor makes a defensive copy of a custom alphabet array. diff --git a/src/main/java/org/apache/commons/codec/binary/Base32.java b/src/main/java/org/apache/commons/codec/binary/Base32.java index ebbb57e353..ad39da408c 100644 --- a/src/main/java/org/apache/commons/codec/binary/Base32.java +++ b/src/main/java/org/apache/commons/codec/binary/Base32.java @@ -17,6 +17,8 @@ package org.apache.commons.codec.binary; +import java.util.Objects; + import org.apache.commons.codec.CodecPolicy; /** @@ -353,6 +355,7 @@ public Base32(final int lineLength, final byte[] lineSeparator, final boolean us */ private Base32(final int lineLength, final byte[] lineSeparator, final byte[] encodeTable, final byte padding, final CodecPolicy decodingPolicy) { super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK, lineLength, toLength(lineSeparator), padding, decodingPolicy); + Objects.requireNonNull(encodeTable, "encodeTable"); this.encodeTable = encodeTable; this.decodeTable = encodeTable == HEX_ENCODE_TABLE ? HEX_DECODE_TABLE : DECODE_TABLE; if (lineLength > 0) {