diff --git a/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java b/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java index 515478821d3faa86b4e0bd09745a93f590497ace..1d33117dd5d89b015d8775c1426850a9c67c07bb 100644 --- a/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java +++ b/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -140,6 +140,9 @@ class CipherBlockChaining extends FeedbackCipher { int encrypt(byte[] plain, int plainOffset, int plainLen, byte[] cipher, int cipherOffset) { + if (plainLen <= 0) { + return plainLen; + } if ((plainLen % blockSize) != 0) { throw new ProviderException("Internal error in input buffering"); } @@ -181,6 +184,9 @@ class CipherBlockChaining extends FeedbackCipher { int decrypt(byte[] cipher, int cipherOffset, int cipherLen, byte[] plain, int plainOffset) { + if (cipherLen <= 0) { + return cipherLen; + } if ((cipherLen % blockSize) != 0) { throw new ProviderException("Internal error in input buffering"); } diff --git a/src/share/classes/com/sun/crypto/provider/CounterMode.java b/src/share/classes/com/sun/crypto/provider/CounterMode.java index af52bd74474d1fe170e231706e3536eeb33b0340..b810b8ff8c7611701fcf8d6fea45779635c8d8e2 100644 --- a/src/share/classes/com/sun/crypto/provider/CounterMode.java +++ b/src/share/classes/com/sun/crypto/provider/CounterMode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -170,6 +170,9 @@ final class CounterMode extends FeedbackCipher { * are encrypted on demand. */ private int crypt(byte[] in, int inOff, int len, byte[] out, int outOff) { + if (len == 0) { + return 0; + } int result = len; while (len-- > 0) { if (used >= blockSize) { diff --git a/src/share/classes/sun/nio/cs/ISO_8859_1.java b/src/share/classes/sun/nio/cs/ISO_8859_1.java index 559f7e1cea81b3edb44bc16badde7d845241bc22..70f61839774475bfe3e2bba694ae908489c908a7 100644 --- a/src/share/classes/sun/nio/cs/ISO_8859_1.java +++ b/src/share/classes/sun/nio/cs/ISO_8859_1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -148,6 +148,7 @@ class ISO_8859_1 private final Surrogate.Parser sgp = new Surrogate.Parser(); // JVM may replace this method with intrinsic code. + // don't pass len value <= 0 private static int encodeISOArray(char[] sa, int sp, byte[] da, int dp, int len) { @@ -180,7 +181,7 @@ class ISO_8859_1 int slen = sl - sp; int len = (dlen < slen) ? dlen : slen; try { - int ret = encodeISOArray(sa, sp, da, dp, len); + int ret = (len <= 0) ? 0 : encodeISOArray(sa, sp, da, dp, len); sp = sp + ret; dp = dp + ret; if (ret != len) { @@ -240,7 +241,8 @@ class ISO_8859_1 int slen = Math.min(len, dst.length); int sl = sp + slen; while (sp < sl) { - int ret = encodeISOArray(src, sp, dst, dp, slen); + int ret = + (slen <= 0) ? 0 : encodeISOArray(src, sp, dst, dp, slen); sp = sp + ret; dp = dp + ret; if (ret != slen) {