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

Base64 MIME decoder should allow unrecognised characters within padding.

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The MIME RFC requires that any character outside of the base64 alphabet be ignored.

      The MIME decoder does this *except* within padding.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      java.util.Base64.getMimeDecoder().decode("AA=!=");

      When two padding characters are appropriate, it should be legal to have characters outside the base64 alphabet between them, as such characters are always ignored.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All characters outside of the base64 alphabet should be ignored, wherever they are, so the above should decode without issue.
      ACTUAL -
      Exception java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
              at Base64$Decoder.decode0 (Base64.java:733)
              at Base64$Decoder.decode (Base64.java:535)
              at Base64$Decoder.decode (Base64.java:558)

      ---------- BEGIN SOURCE ----------
      java.util.Base64.getMimeDecoder().decode("AA=!=");
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Input can be sanitised to remove characters outside of the base64 alphabet prior to processing. For example:

      input = input.replaceAll("[^A-Za-z0-9+/=]","");

      FREQUENCY : always


            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: