Author: centic
Date: Wed Apr  4 19:41:16 2018
New Revision: 1828378

URL: http://svn.apache.org/viewvc?rev=1828378&view=rev
Log:
Close resources correctly when opening encrypted documents in the TextExtractor

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java?rev=1828378&r1=1828377&r2=1828378&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java Wed 
Apr  4 19:41:16 2018
@@ -132,7 +132,7 @@ public class ExtractorFactory {
         try {
             fs = new NPOIFSFileSystem(f);
             if (fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
-                return createEncyptedOOXMLExtractor(fs);
+                return createEncryptedOOXMLExtractor(fs);
             }
             POIOLE2TextExtractor extractor = createExtractor(fs);
             extractor.setFilesystem(fs);
@@ -161,7 +161,7 @@ public class ExtractorFactory {
         case OLE2:
             NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
             boolean isEncrypted = 
fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY); 
-            return isEncrypted ? createEncyptedOOXMLExtractor(fs) : 
createExtractor(fs);
+            return isEncrypted ? createEncryptedOOXMLExtractor(fs) : 
createExtractor(fs);
         case OOXML:
             return createExtractor(OPCPackage.open(is));
         default:
@@ -403,7 +403,7 @@ public class ExtractorFactory {
         throw new IllegalStateException("Not yet supported");
     }
     
-    private static POIXMLTextExtractor 
createEncyptedOOXMLExtractor(NPOIFSFileSystem fs)
+    private static POIXMLTextExtractor 
createEncryptedOOXMLExtractor(NPOIFSFileSystem fs)
     throws IOException {
         String pass = Biff8EncryptionKey.getCurrentUserPassword();
         if (pass == null) {
@@ -425,6 +425,10 @@ public class ExtractorFactory {
             throw new EncryptedDocumentException(e);
         } finally {
             IOUtils.closeQuietly(is);
+
+            // also close the NPOIFSFileSystem here as we read all the data
+            // while decrypting
+            fs.close();
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to