提交 229b93d5 编写于 作者: A ascarpino

8042480: CipherInputStream.close() throws AEADBadTagException in some cases

Reviewed-by: xuelei
上级 07d094ed
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -88,6 +88,8 @@ public class CipherInputStream extends FilterInputStream { ...@@ -88,6 +88,8 @@ public class CipherInputStream extends FilterInputStream {
private int ofinish = 0; private int ofinish = 0;
// stream status // stream status
private boolean closed = false; private boolean closed = false;
// The stream has been read from. False if the stream has never been read.
private boolean read = false;
/** /**
* private convenience function. * private convenience function.
...@@ -103,6 +105,7 @@ public class CipherInputStream extends FilterInputStream { ...@@ -103,6 +105,7 @@ public class CipherInputStream extends FilterInputStream {
private int getMoreData() throws IOException { private int getMoreData() throws IOException {
if (done) return -1; if (done) return -1;
int readin = input.read(ibuffer); int readin = input.read(ibuffer);
read = true;
if (readin == -1) { if (readin == -1) {
done = true; done = true;
try { try {
...@@ -312,7 +315,11 @@ public class CipherInputStream extends FilterInputStream { ...@@ -312,7 +315,11 @@ public class CipherInputStream extends FilterInputStream {
} }
} }
catch (BadPaddingException | IllegalBlockSizeException ex) { catch (BadPaddingException | IllegalBlockSizeException ex) {
throw new IOException(ex); /* If no data has been read from the stream to be en/decrypted,
we supress any exceptions, and close quietly. */
if (read) {
throw new IOException(ex);
}
} }
ostart = 0; ostart = 0;
ofinish = 0; ofinish = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册