You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2019/11/25 15:09:05 UTC

[GitHub] [commons-codec] garydgregory commented on a change in pull request #29: [CODEC-270] Base32/64: Fix masked check of the final bits to discard.

garydgregory commented on a change in pull request #29: [CODEC-270] Base32/64: Fix masked check of the final bits to discard.
URL: https://github.com/apache/commons-codec/pull/29#discussion_r350238940
 
 

 ##########
 File path: src/main/java/org/apache/commons/codec/binary/Base32.java
 ##########
 @@ -548,19 +561,23 @@ public boolean isInAlphabet(final byte octet) {
     }
 
     /**
-     * <p>
-     * Validates whether the character is possible in the context of the set of possible base 32 values.
-     * </p>
+     * Validates whether decoding the final trailing character is possible in the context
+     * of the set of possible base 32 values.
+     *
+     * <p>The character is valid if the lower bits within the provided mask are zero. This
+     * is used to test the final trailing base-32 digit is zero in the bits that will be discarded.
      *
-     * @param numBits number of least significant bits to check
+     * @param emptyBitsMask The mask of the lower bits that should be empty
      * @param context the context to be used
      *
      * @throws IllegalArgumentException if the bits being checked contain any non-zero value
      */
-    private void validateCharacter(final int numBits, final Context context) {
-        if ((context.lbitWorkArea & numBits) != 0) {
-            throw new IllegalArgumentException(
-                "Last encoded character (before the paddings if any) is a valid base 32 alphabet but not a possible value");
+    private static void validateCharacter(final long emptyBitsMask, final Context context) {
+        // Use the long bit work area
+        if ((context.lbitWorkArea & emptyBitsMask) != 0) {
+        throw new IllegalArgumentException(
 
 Review comment:
   Indentation is not quite right for the guts of this `if` block.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services