Mercurial > hg > openjdk > jdk8u > jdk
changeset 12801:71dee2264ddd jdk8u144-b34
8159035: CTSMode.java test crashed due to unhandled case of cipher length value as 0
Reviewed-by: ascarpino
author | coffeys |
---|---|
date | Mon, 28 Aug 2017 14:55:58 +0100 |
parents | 6ea9dfcf31f6 |
children | 142b01c8fc80 |
files | src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java src/share/classes/com/sun/crypto/provider/CounterMode.java src/share/classes/sun/nio/cs/ISO_8859_1.java |
diffstat | 3 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java Fri Sep 01 11:15:29 2017 -0700 +++ b/src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java Mon Aug 28 14:55:58 2017 +0100 @@ -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 @@ 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 @@ 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"); }
--- a/src/share/classes/com/sun/crypto/provider/CounterMode.java Fri Sep 01 11:15:29 2017 -0700 +++ b/src/share/classes/com/sun/crypto/provider/CounterMode.java Mon Aug 28 14:55:58 2017 +0100 @@ -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 @@ * 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) {
--- a/src/share/classes/sun/nio/cs/ISO_8859_1.java Fri Sep 01 11:15:29 2017 -0700 +++ b/src/share/classes/sun/nio/cs/ISO_8859_1.java Mon Aug 28 14:55:58 2017 +0100 @@ -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 @@ 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 @@ 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 @@ 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) {