This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new b672f947 Internal bullet proofing
b672f947 is described below

commit b672f947024ac400a4bbb06fe3b92fbad172e9c7
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Jul 9 08:53:17 2026 -0400

    Internal bullet proofing
---
 .../java/org/apache/commons/codec/binary/BaseNCodec.java  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java 
b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
index 08d9ef31..bf32569d 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
@@ -176,7 +176,7 @@ public abstract class BaseNCodec implements BinaryEncoder, 
BinaryDecoder {
          * @return {@code this} instance.
          */
         B setEncodedBlockSize(final int encodedBlockSize) {
-            this.encodedBlockSize = encodedBlockSize;
+            this.encodedBlockSize = gte0(encodedBlockSize);
             return asThis();
         }
 
@@ -242,7 +242,7 @@ public abstract class BaseNCodec implements BinaryEncoder, 
BinaryDecoder {
          * @return {@code this} instance.
          */
         B setUnencodedBlockSize(final int unencodedBlockSize) {
-            this.unencodedBlockSize = unencodedBlockSize;
+            this.unencodedBlockSize = gte0(unencodedBlockSize);
             return asThis();
         }
     }
@@ -425,6 +425,13 @@ public abstract class BaseNCodec implements BinaryEncoder, 
BinaryDecoder {
         return array == null ? 0 : array.length;
     }
 
+    private static int gte0(int value) {
+        if (value < 0) {
+            throw new IllegalArgumentException("value must be greater than or 
equal to 0.");
+        }
+        return value;
+    }
+
     /**
      * Tests whether or not the {@code value} is in the given {@code table}.
      *
@@ -535,8 +542,8 @@ public abstract class BaseNCodec implements BinaryEncoder, 
BinaryDecoder {
      * @since 1.20.0
      */
     protected BaseNCodec(final AbstractBuilder<?, ?> builder) {
-        this.unencodedBlockSize = builder.unencodedBlockSize;
-        this.encodedBlockSize = builder.encodedBlockSize;
+        this.unencodedBlockSize = gte0(builder.unencodedBlockSize);
+        this.encodedBlockSize = gte0(builder.encodedBlockSize);
         final boolean useChunking = builder.lineLength > 0 && 
builder.lineSeparator.length > 0;
         this.lineLength = useChunking ? builder.lineLength / 
builder.encodedBlockSize * builder.encodedBlockSize : 0;
         this.chunkSeparatorLength = builder.lineSeparator.length;

Reply via email to