Bug 32904

Summary: Typo in Base64.java's decode function
Product: gcc Reporter: Troy Korjuslommi <tjk>
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: gcc-bugs, java-prs
Priority: P3    
Version: 4.2.1   
Target Milestone: ---   
Host: i486-pc-linux-gnu Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2007-07-26 16:19:36

Description Troy Korjuslommi 2007-07-26 14:49:41 UTC
There is a typo in libjava/classpath/gnu/java/security/util/Base64.java's
decode function.
public static byte[] decode(final byte[] src, final int off, final int len) {... }

The following loop ends up throwing an exception on correct input.
A "continue" line is missing, as shown below.
When the continue line is added, the function works correctly.

for (i = off; i < off + len; i++)
      {
        sbiCrop = (byte) (src[i] & 0x7F); // Only the low seven bits
        sbiDecode = DECODABET[sbiCrop];
        if (sbiDecode >= WHITE_SPACE_ENC)
          { // White space, Equals sign or better
            if (sbiDecode >= EQUALS_SIGN_ENC)
              {
                b4[b4Posn++] = sbiCrop;
                if (b4Posn > 3)
                  {
                    outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn);
                    b4Posn = 0;
                    // If that was the equals sign, break out of 'for' loop
                    if (sbiCrop == EQUALS_SIGN)
                      break;
                  } // end if: quartet built
              } // end if: equals sign or better
            // ERROR HERE: The following line is missing.
            // continue;
          }
        throw new IllegalArgumentException("Illegal BASE-64 character at #"
                                           + i + ": " + src[i] + "(decimal)");
      }
Comment 1 Tom Tromey 2007-07-26 16:19:36 UTC
Note that this is fixed in Classpath and gcj 4.3.
As I recall, Casey (? I think) consolidated all the Base64
implementations into a single good one.