This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3cb3ff6f8e Build the cipher before opening the zip entry in
AesZipFileZipEntrySource (#1252)
3cb3ff6f8e is described below
commit 3cb3ff6f8e1de997996b853a11016a30dc986816
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Sep 7 13:27:10 2026 +0100
Build the cipher before opening the zip entry in AesZipFileZipEntrySource
(#1252)
AesZipFileZipEntrySource.getInputStream opened the entry's stream first
and then built the decryption cipher:
InputStream is = zipFile.getInputStream(entry);
return new CipherInputStream(is, getCipher(Cipher.DECRYPT_MODE));
getCipher delegates to CryptoFunctions.getCipher, which throws
EncryptedDocumentException when the JCE cannot supply the cipher. That
happens after the entry stream is open and nothing has taken ownership of
it, so the stream leaks.
Swap the order so the cipher is built first and the entry is only opened
once it is known to succeed. EncryptedTempData.getInputStream already
uses this ordering.
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
.../org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
index ac55fe843b..034161a7f1 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
@@ -89,8 +89,11 @@ public final class AesZipFileZipEntrySource implements
ZipEntrySource {
@Override
public InputStream getInputStream(ZipArchiveEntry entry) throws
IOException {
+ // build the cipher before opening the entry - getCipher can throw
+ // EncryptedDocumentException, which would otherwise leak the open
stream
+ Cipher ciDec = getCipher(Cipher.DECRYPT_MODE);
InputStream is = zipFile.getInputStream(entry);
- return new CipherInputStream(is, getCipher(Cipher.DECRYPT_MODE));
+ return new CipherInputStream(is, ciDec);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]