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: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, gnu_andrew, 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.
Comment 2 Andrew Pinski 2016-09-30 22:50:34 UTC
Closing as won't fix as the Java front-end has been removed from the trunk.
Comment 3 Andrew John Hughes 2016-10-03 17:29:10 UTC
Base64 implementation is now gnu/java/util/Base64.java without this mistake in both Classpath and gcj.