JDK-8007433 : Base64.Decoder.decode(ByteBuffer, ByteBuffer) doesn't throw IAE for non-valid Base64 if writing could not be done
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8
  • Priority: P2
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-02-02
  • Updated: 2014-12-03
  • Resolved: 2014-12-03
Related Reports
Duplicate :  
Description
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]


Comments
JDK-8006530
03-12-2014

another format of affected tests for automatic failure analysis: api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_Basic api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_URL api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME api/java_util/Base64/Decoder/index.html#DecodingNonValidBase64Scheme_MIME
27-03-2013

IAE now gets thrown, after the change for 8006530. I closed it as the dup of it.
04-02-2013