This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
The following commit(s) were added to refs/heads/master by this push: new 34a37c9 PositionedCryptoInputStream does not close its CryptoCipher instances 34a37c9 is described below commit 34a37c9d27dc77d3fbccc9ef996dc7b28bb74315 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Dec 11 12:33:34 2022 -0500 PositionedCryptoInputStream does not close its CryptoCipher instances --- src/changes/changes.xml | 3 ++- .../crypto/stream/PositionedCryptoInputStream.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ad0a889..b6d8c7d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -61,7 +61,7 @@ --> <body> - <release version="1.1.1" date="20YY-MM-DD" description="TBD"> + <release version="1.2.0" date="202Y-MM-DD" description="Minor release"> <action issue="CRYPTO-160" type="fix" dev="jochen">Enhance the quality of JavaCryptoRandom as a subclass of Random by overwriting Random.next(int).</action> <!-- FIX --> <action issue="CRYPTO-163" type="fix">Makefile does not recompile objects if local include files are changed</action> @@ -72,6 +72,7 @@ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 11.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 17.</action> <action issue="CRYPTO-155" type="fix" due-to="Arturo Bernal">Minor improvement #115, #125.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">PositionedCryptoInputStream does not close its CryptoCipher instances.</action> <!-- ADD --> <action type="fix" dev="ggregory" due-to="Gary Gregory, Dependabot">Add github/codeql-action 2 #159.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory, Dependabot">Add AES utility class.</action> diff --git a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java index 632a552..5a180fb 100644 --- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java @@ -136,13 +136,25 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream { } /** Cleans direct buffer pool */ - private void cleanBufferPool() { + private void cleanByteBufferPool() { ByteBuffer buf; while ((buf = byteBufferPool.poll()) != null) { CryptoInputStream.freeDirectBuffer(buf); } } + /** Cleans direct buffer pool */ + private void cleanCipherStatePool() { + CipherState cs; + while ((cs = cipherStatePool.poll()) != null) { + try { + cs.getCryptoCipher().close(); + } catch (IOException ignored) { + // ignore + } + } + } + /** * Overrides the {@link CryptoInputStream#close()}. Closes this input stream * and releases any system resources associated with the stream. @@ -155,7 +167,8 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream { return; } - cleanBufferPool(); + cleanByteBufferPool(); + cleanCipherStatePool(); super.close(); } @@ -277,6 +290,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream { * @return the CipherState instance. * @throws IOException if an I/O error occurs. */ + @SuppressWarnings("resource") // Caller calls #returnToPool(CipherState) private CipherState getCipherState() throws IOException { CipherState state = cipherStatePool.poll(); return state != null ? state : new CipherState(Utils.getCipherInstance(AES.CTR_NO_PADDING, properties));