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);