changeset 9848:a6be8ac1dcc5

8042480: CipherInputStream.close() throws AEADBadTagException in some cases Reviewed-by: xuelei
author ascarpino
date Sun, 18 May 2014 23:06:25 +0000
parents 73db59b9e7e1
children ef47bc58427d 4339234f3716
files src/share/classes/javax/crypto/CipherInputStream.java
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/crypto/CipherInputStream.java	Tue May 27 06:52:16 2014 -0400
+++ b/src/share/classes/javax/crypto/CipherInputStream.java	Sun May 18 23:06:25 2014 +0000
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -88,6 +88,8 @@
     private int ofinish = 0;
     // stream status
     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.
@@ -103,6 +105,7 @@
     private int getMoreData() throws IOException {
         if (done) return -1;
         int readin = input.read(ibuffer);
+        read = true;
         if (readin == -1) {
             done = true;
             try {
@@ -312,7 +315,11 @@
             }
         }
         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;
         ofinish = 0;