JDK-8013923 : Base64.getMimeDecoder().decode() does not ignore padding chars
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8
  • Priority: P2
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-05-06
  • Updated: 2013-05-07
  • Resolved: 2013-05-07
Related Reports
Relates :  
Relates :  
Description
The spec http://download.java.net/jdk8/docs/api/java/util/Base64.html says: 

"MIME 
... All line separators or other characters not found in the base64 alphabet table are ignored in decoding operation." 

For *JDK8 b88* this is not so if the decoded string has to-be-ignored padding character. 
The following code produces an IAE: 

---------------------------------------------------------------------- 
import java.util.Base64; 

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

This problem exists for all decoding methods for a MIME decoder. 

Exception in thread "main" java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit 
at java.util.Base64$Decoder.decode0(Base64.java:1076) 
at java.util.Base64$Decoder.decode(Base64.java:695) 
at java.util.Base64$Decoder.decode(Base64.java:718) 
at StartsWithPadding.main(StartsWithPadding.java:8) 


The following testcases will fail due to this issue: 

api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[downToZero_severalChars] 
api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[downToZero_twoChars] 
api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[validInput_ignoredSeveralCharsAtTheBeginning] 
api/java_util/Base64/Decoder/index.html#MimeDec_NonBase64CharsIgnored[validInput_ignoredSeveralCharsAtTheEnd] 

api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[wrapDecode_threeBase64Chars_ignoredInTheMiddle] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[wrapDecode_threeBase64Chars_ignoredInTheBeginning] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decode_twoBase64Chars_ignoredInTheMiddle] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decode_twoBase64Chars_ignoredInTheEnd] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decode_twoBase64Chars_ignoredAtTheBeginning] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decode_threeBase64Chars_ignoredInTheMiddle] 
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[ decode_threeBase64Chars_ignoredInTheBeginning] 
Comments
dup of #9013902
07-05-2013

Might be a duplicate of JDK-8013902. Looks like the same bug but different test failures.
06-05-2013