提交 a35baaf9 编写于 作者: C coffeys

8159035: CTSMode.java test crashed due to unhandled case of cipher length value as 0

Reviewed-by: ascarpino
上级 f674bbaf
/*
* 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");
}
......
/*
* 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) {
......
/*
* 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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册