Hi,

Looks like the Codec people made a call on the non-Base64 data handling. It seems we were throwing out all non Base64 data in the discardWhitespace function. From this patch, it looks like they "undid" that.

Is this going to reopen our bug report?

--
Ryan Hoegg
ISIS Networks
http://www.isisnetworks.net
--- Begin Message ---
tobrien     2003/03/03 00:12:35

  Modified:    codec/src/java/org/apache/commons/codec/binary Base64.java
  Log:
  Insidious bug in Base64 that was in essence nullifying isArrayByteBase64 by 
discarding non-base64 content along with whitespace.  The lesson to learn here is that 
if you name a function 'discardWhitespace' stick to that name, don't exceed the name 
of the function.  The only reason we found this bug was because of Clover.
  
  Revision  Changes    Path
  1.10      +16 -20    
jakarta-commons-sandbox/codec/src/java/org/apache/commons/codec/binary/Base64.java
  
  Index: Base64.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/codec/src/java/org/apache/commons/codec/binary/Base64.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Base64.java       3 Mar 2003 04:17:52 -0000       1.9
  +++ Base64.java       3 Mar 2003 08:12:35 -0000       1.10
  @@ -106,7 +106,7 @@
       // Populating the lookup and character arrays

       static {

           for (int i = 0; i < BASELENGTH; i++) {

  -            base64Alphabet[i] = -1;

  +            base64Alphabet[i] = (byte) -1;

           }

           for (int i = 'Z'; i >= 'A'; i--) {

               base64Alphabet[i] = (byte) (i - 'A');

  @@ -138,11 +138,18 @@
       }

   

       private static boolean isBase64(byte octect) {

  -        //shall we ignore white space? JEFF??

  -        return (octect == PAD || base64Alphabet[octect] != -1);

  +        if( octect == PAD ) {

  +            return true;

  +        } 

  +        else if( base64Alphabet[octect] == -1 ) {

  +            return false;

  +        } else {

  +            return true;

  +        }

       }

   

       public static boolean isArrayByteBase64(byte[] arrayOctect) {

  +

           arrayOctect = discardWhitespace(arrayOctect);

   

           int length = arrayOctect.length;

  @@ -152,7 +159,7 @@
               return true;

           }

           for (int i = 0; i < length; i++) {

  -            if (!Base64.isBase64(arrayOctect[i])) {

  +            if ( !isBase64(arrayOctect[i]) ) {

                   return false;

               }

           }

  @@ -433,11 +440,6 @@
       /**

        * Discards any whitespace from a base-64 encoded block.

        *

  -     * Any other non-base-64 characters will be silently

  -     * discarded. This complies with the RFC, although a warning or

  -     * exception would also be RFC compliant (and is actually

  -     * recommended).

  -     *

        * @param data The base-64 encoded data to discard the whitespace

        * from.

        * @return The data, less whitespace (see RFC 2045).

  @@ -453,14 +455,8 @@
                   case (byte) '\r' :

                   case (byte) '\t' :

                       break;

  -                default :

  -                    if (isBase64(data[i])) {

  -                        groomedData[bytesCopied++] = data[i];

  -                    } 

  -                    else {

  -                        // according to the RFC, we could raise a warning

  -                        // or exception here

  -                    }

  +                default:

  +                    groomedData[bytesCopied++] = data[i];

               }

           }

   

  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--- End Message ---

Reply via email to