--- old/src/java.base/share/classes/sun/security/provider/DigestBase.java 2015-06-25 12:09:49.386654559 +0200 +++ new/src/java.base/share/classes/sun/security/provider/DigestBase.java 2015-06-25 12:09:48.870654535 +0200 @@ -28,6 +28,9 @@ import java.security.MessageDigestSpi; import java.security.DigestException; import java.security.ProviderException; +import java.util.Objects; + +import jdk.internal.HotSpotIntrinsicCandidate; /** * Common base message digest implementation for the Sun provider. @@ -136,12 +139,36 @@ // compress complete blocks private int implCompressMultiBlock(byte[] b, int ofs, int limit) { + implCompressMultiBlockCheck(b, ofs, limit); + return implCompressMultiBlockImpl(b, ofs, limit); + } + + @HotSpotIntrinsicCandidate + private int implCompressMultiBlockImpl(byte[] b, int ofs, int limit) { for (; ofs <= limit; ofs += blockSize) { implCompress(b, ofs); } return ofs; } + private void implCompressMultiBlockCheck(byte[] b, int ofs, int limit) { + if (limit < 0) { + return; // not an error because implCompressMultiBlockImpl won't execute if limit < 0 + // and an exception is thrown if ofs < 0. + } + + Objects.requireNonNull(b); + + if (ofs < 0 || ofs >= b.length) { + throw new ArrayIndexOutOfBoundsException(ofs); + } + + int endIndex = (limit / blockSize) * blockSize + blockSize - 1; + if (endIndex >= b.length) { + throw new ArrayIndexOutOfBoundsException(endIndex); + } + } + // reset this object. See JCA doc. protected final void engineReset() { if (bytesProcessed == 0) {