From e8263f9d8f7e24828e2c6c2ce82e364463bc61c7 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 2 Apr 2016 11:01:56 +0000 Subject: [PATCH] Fix two more places where wrong/invalid files can lead to file-handle leaks currently git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737489 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/openxml4j/opc/OPCPackage.java | 1 + .../org/apache/poi/openxml4j/opc/internal/ZipHelper.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 3eb9b6df6..b1b11b512 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -429,6 +429,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { if (this.contentTypeManager == null) { logger.log(POILogger.WARN, "Unable to call close() on a package that hasn't been fully opened yet"); + revert(); return; } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java index 56536d238..632d2af26 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java @@ -247,8 +247,11 @@ public final class ZipHelper { // Peek at the first few bytes to sanity check FileInputStream input = new FileInputStream(file); - verifyZipHeader(input); - input.close(); + try { + verifyZipHeader(input); + } finally { + input.close(); + } // Open as a proper zip file return new ZipSecureFile(file);