From 740932ee85c1d465933ebfd306bcc4bc5795f070 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 9 Oct 2016 20:34:35 +0000 Subject: [PATCH] Bug 60230 - Roundtrip test that encrypts XSSFWorkbook and then decrypts it fails with latest code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1764008 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/poifs/crypt/ChunkedCipherInputStream.java | 2 +- .../org/apache/poi/xssf/TestWorkbookProtection.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java index 8999b6e0dd..1045b3058b 100644 --- a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java +++ b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java @@ -199,7 +199,7 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { System.arraycopy(_plain, 0, _chunk, 0, totalBytes); - invokeCipher(totalBytes, _chunkSize > -1); + invokeCipher(totalBytes, totalBytes == _chunkSize); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java b/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java index b216a46d5f..9c7e9355dd 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java @@ -189,7 +189,6 @@ public class TestWorkbookProtection { assertTrue(wb.validateRevisionsPassword("test")); } - @Ignore("bug 60230: currently failing due to regression from bug 59857 r1762726") @Test public void testEncryptDecrypt() throws Exception { final String password = "abc123"; @@ -208,7 +207,9 @@ public class TestWorkbookProtection { EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile); Encryptor enc = encryptionInfo.getEncryptor(); enc.confirmPassword(password); - OPCPackage opc = OPCPackage.open(new FileInputStream(tf1)); + FileInputStream fis = new FileInputStream(tf1); + OPCPackage opc = OPCPackage.open(fis); + IOUtils.closeQuietly(fis); try { OutputStream os = enc.getDataStream(poiFileSystem); opc.save(os); @@ -221,7 +222,9 @@ public class TestWorkbookProtection { poiFileSystem.writeFilesystem(fos2); IOUtils.closeQuietly(fos2); workbook.close(); - POIFSFileSystem poiFileSystem2 = new POIFSFileSystem(new FileInputStream(tf1)); + fis = new FileInputStream(tf1); + POIFSFileSystem poiFileSystem2 = new POIFSFileSystem(fis); + IOUtils.closeQuietly(fis); EncryptionInfo encryptionInfo2 = new EncryptionInfo(poiFileSystem2); Decryptor decryptor = encryptionInfo2.getDecryptor(); decryptor.verifyPassword(password); -- 2.39.5