Base64.Decoder.decode(ByteBuffer, ByteBuffer) doesn't throw IAE for a non-valid Base64 bytes if writing to output buffer could not be done - it's either zero size or its position is at its limit
This problem happens with basic, urlsafe and mime decoders.
Please see the following code sample:
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class NoIAE {
public static void main(String[] args) {
final Base64.Decoder decoder = Base64.getDecoder();
final byte[] invalidBytes = "QU=I=".getBytes(StandardCharsets.US_ASCII);
decoder.decode(
ByteBuffer.wrap(invalidBytes),
ByteBuffer.allocate(0));
decoder.decode(
ByteBuffer.wrap(invalidBytes),
(ByteBuffer)ByteBuffer.allocate(100).position(100));
}
}
The following JCK tests will fail due to this issue
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic[decodeBufferInvalidBase64_nowhereToWrite_emptyByteBuffer]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic[decodeBufferInvalidBase64_nowhereToWrite_fullByteBuffer]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL[decodeBufferInvalidBase64_nowhereToWrite_emptyByteBuffer]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL[decodeBufferInvalidBase64_nowhereToWrite_fullByteBuffer]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decodeBufferInvalidBase64_nowhereToWrite_emptyByteBuffer]
api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME[decodeBufferInvalidBase64_nowhereToWrite_fullByteBuffer]