JDK-8007379 : Base64.getMimeDecoder().decode() throws IAE for a non-base64 character after padding
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-02-01
  • Updated: 2021-01-18
  • Resolved: 2013-04-02
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
Duplicate :  
Relates :  
Relates :  
Description
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] 

Comments
looks like also affected: api/java_util/Base64/index.html#Samples[phrase_01_decodeToByteBuffer]
01-04-2013

issue still exists in b78
25-02-2013

Still getting IAE with b78 --- import java.nio.charset.StandardCharsets; import java.util.Base64; public class OutByteArrayIsTooSmall { public static void main(String[] args) { final byte[] expected = "fo".getBytes(StandardCharsets.US_ASCII); byte[] dst = new byte[expected.length]; Base64.getMimeDecoder().decode("Zm8=\r\n".getBytes(StandardCharsets.US_ASCII), dst); } } --- Exception in thread "main" java.lang.IllegalArgumentException: Output byte array is too small for decoding all input bytes at java.util.Base64$Decoder.decode(Base64.java:749) at OutByteArrayIsTooSmall.main(OutByteArrayIsTooSmall.java:9)
25-02-2013

It's a dup of 8006530. The latest push has fixed this issue (to ignore any non-base64 characters after padding character '=', if it's a MIME decoder)
04-02-2013