]> source.dussan.org Git - poi.git/commitdiff
close input streams for parts
authorPJ Fanning <fanningpj@apache.org>
Tue, 28 Dec 2021 02:48:28 +0000 (02:48 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 28 Dec 2021 02:48:28 +0000 (02:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896464 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java
poi-ooxml/src/main/java/org/apache/poi/xssf/binary/XSSFBSharedStringsTable.java
poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java

index d01724a923d0d53706c1c4ad0b2d9f23bc0dac75..cc450fc8ec67c4f8fe2397229cafa48725bfe6ce 100644 (file)
@@ -36,6 +36,7 @@ import javax.xml.crypto.URIReference;
 import javax.xml.crypto.URIReferenceException;
 import javax.xml.crypto.XMLCryptoContext;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -81,7 +82,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
             return baseUriDereferencer.dereference(uriReference, context);
         }
 
-        InputStream dataStream;
+        InputStream dataStream = null;
         try {
             dataStream = part.getInputStream();
 
@@ -99,6 +100,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
                 }
             }
         } catch (IOException e) {
+            IOUtils.closeQuietly(dataStream);
             throw new URIReferenceException("I/O error: " + e.getMessage(), e);
         }
 
index f658482b0979b31910ff2b8e96659a050444f96c..ad566183f91b5a3d9ffaa84aef6837e2a4e69f96 100644 (file)
@@ -68,8 +68,9 @@ public class XSSFBSharedStringsTable implements SharedStrings {
         // Some workbooks have no shared strings table.
         if (parts.size() > 0) {
             PackagePart sstPart = parts.get(0);
-
-            readFrom(sstPart.getInputStream());
+            try (InputStream stream = sstPart.getInputStream()) {
+                readFrom(stream);
+            }
         }
     }
 
index 0ca6e685df0d54965c3cd80ca44654e780c4430a..2f0c958260d51a75a01e6f5f61d2f8d8f0a5b169 100644 (file)
@@ -131,7 +131,9 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared
         // Some workbooks have no shared strings table.
         if (parts.size() > 0) {
             PackagePart sstPart = parts.get(0);
-            readFrom(sstPart.getInputStream());
+            try (InputStream stream = sstPart.getInputStream()) {
+                readFrom(stream);
+            }
         }
     }
 
index c8f7fba0f754952991fb54b77d780baa879ff859..deebf72836cce0b13439b1a3528b459f0d96a1a2 100644 (file)
@@ -165,7 +165,9 @@ public class XSSFBReader extends XSSFReader {
                     }
                     PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI());
                     PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName);
-                    return new XSSFBCommentsTable(commentsPart.getInputStream());
+                    try (InputStream stream = commentsPart.getInputStream()) {
+                        return new XSSFBCommentsTable(stream);
+                    }
                 }
             } catch (InvalidFormatException | IOException e) {
                 return null;