Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8007379

Base64.getMimeDecoder().decode() throws IAE for a non-base64 character after padding

XMLWordPrintable

    • b86
    • Verified

      Mime decoder does not ignore non-Base64 chars that appear after padding ('=')

      import java.util.Base64;

      public class CharToIgnoreAtTheEnd {

          public static void main(String[] args) {
              Base64.getMimeDecoder().decode("bGVhc3VyZS4=$");
          }
      }

      The output is

      Exception in thread "main" java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
      at java.util.Base64$Decoder.decode0(Base64.java:1080)
      at java.util.Base64$Decoder.decode(Base64.java:686)
      at java.util.Base64$Decoder.decode(Base64.java:709)
      at CharToIgnoreAtTheEnd.main(CharToIgnoreAtTheEnd.java:6)


      The following JCK tests will fail due to this issue:

      api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[validInput_ignoredCharAtTheEnd]
      api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[lineSeparatorInTheEnd]
      api/java_util/Base64/index.html#Samples[phrase_01_decodeToByteArray]

            sherman Xueming Shen
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: