JDK-8008925 : Base64.getMimeDecoder().decode() does not ignore padding chars
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-02-25
  • Updated: 2013-05-07
  • Resolved: 2013-05-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b86Fixed
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."

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
Moved back to status = Closed, Resolution = Fixed, per Alan Bateman, who noted that both spec and tests have changed since the changeset for this bug has been integrated.
06-05-2013

Adjusting to status = Closed, resolution = Fix Failed.
06-05-2013

Filed JDK-8013923. Problem is still seen with b88
06-05-2013

Dmitrij - can you please open a new bug for the issue you are seeing? We can't re-open and re-use old bug numbers once there is a change pushed. I have closed this bug and restored the fixed-in-build so that JIRA matches the repository.
04-05-2013

Problem still reproducible in b87 by mentioned code above (class StartsWithPadding).
04-05-2013

Here is test name for Aurora matching: api/java_util/Base64/Decoder/index_DecodingNonValidBase64Scheme_MIME[decode_threeBase64Chars_ignoredInTheBeginning]
18-03-2013