8042480: CipherInputStream.close() throws AEADBadTagException in some cases
Reviewed-by: xuelei
This commit is contained in:
parent
05ed094d99
commit
0d4528c45f
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 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 {
|
|||||||
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 {
|
|||||||
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 {
|
||||||
@ -306,8 +309,12 @@ public class CipherInputStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (BadPaddingException | IllegalBlockSizeException ex) {
|
catch (BadPaddingException | IllegalBlockSizeException 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);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ostart = 0;
|
ostart = 0;
|
||||||
ofinish = 0;
|
ofinish = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user