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
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
- relates to
-
JDK-8007379 Base64.getMimeDecoder().decode() throws IAE for a non-base64 character after padding
-
- Closed
-