Description
The spec on java.util.Base64.Decoder
http://download.java.net/jdk8/docs/api/java/util/Base64.Decoder.html
says:
"If there is padding character present in the final unit, the correct number of padding character(s) must be present, otherwise IllegalArgumentException is thrown during decoding."
However this assertion is not satisfied for decoding approach using InputStream:
The following code sample would not throw IOE as expected for decoding invalid stream:
---------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class WrongNumOfPChars {
public static void main(String[] args) throws IOException {
final byte[] bytes = "AA=".getBytes(StandardCharsets.US_ASCII);
final InputStream stream = Base64.getDecoder().wrap(new ByteArrayInputStream(bytes));
while (stream.read() != -1);
}
}
the following JCK tests will fail due to this issue:
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[wrapDecode_endsWithWrongPadding2]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic[wrapDecode_endsWithWrongPadding2]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL[wrapDecode_endsWithWrongPadding2]
http://download.java.net/jdk8/docs/api/java/util/Base64.Decoder.html
says:
"If there is padding character present in the final unit, the correct number of padding character(s) must be present, otherwise IllegalArgumentException is thrown during decoding."
However this assertion is not satisfied for decoding approach using InputStream:
The following code sample would not throw IOE as expected for decoding invalid stream:
---------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class WrongNumOfPChars {
public static void main(String[] args) throws IOException {
final byte[] bytes = "AA=".getBytes(StandardCharsets.US_ASCII);
final InputStream stream = Base64.getDecoder().wrap(new ByteArrayInputStream(bytes));
while (stream.read() != -1);
}
}
the following JCK tests will fail due to this issue:
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[wrapDecode_endsWithWrongPadding2]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic[wrapDecode_endsWithWrongPadding2]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL[wrapDecode_endsWithWrongPadding2]