From 5585f34da058f4141f3c9cc2b33bd1c6ea17dc51 Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Wed, 31 Oct 2018 00:59:16 +0000 Subject: [PATCH] bug 62624 -- ensure streams are closed...thanks to LGTM, and PJ! git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845300 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/poifs/macros/VBAMacroReader.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java index 6c112c213e..8ba36e7a95 100644 --- a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java +++ b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java @@ -350,8 +350,9 @@ public class VBAMacroReader implements Closeable { for (Entry entry : node) { if ("project".equalsIgnoreCase(entry.getName())) { DocumentNode document = (DocumentNode)entry; - DocumentInputStream dis = new DocumentInputStream(document); - readProjectProperties(dis, moduleNameMap, modules); + try(DocumentInputStream dis = new DocumentInputStream(document)) { + readProjectProperties(dis, moduleNameMap, modules); + } } else if (entry instanceof DirectoryNode) { findProjectProperties((DirectoryNode)entry, moduleNameMap, modules); } @@ -362,8 +363,9 @@ public class VBAMacroReader implements Closeable { for (Entry entry : node) { if ("projectwm".equalsIgnoreCase(entry.getName())) { DocumentNode document = (DocumentNode)entry; - DocumentInputStream dis = new DocumentInputStream(document); - readNameMapRecords(dis, moduleNameMap, modules.charset); + try(DocumentInputStream dis = new DocumentInputStream(document)) { + readNameMapRecords(dis, moduleNameMap, modules.charset); + } } else if (entry.isDirectoryEntry()) { findModuleNameMap((DirectoryNode)entry, moduleNameMap, modules); } @@ -485,7 +487,7 @@ public class VBAMacroReader implements Closeable { try (DocumentInputStream dis = new DocumentInputStream(dirDocumentNode)) { String streamName = null; int recordId = 0; - boolean inReferenceTwiddled = false; + try (RLEDecompressingInputStream in = new RLEDecompressingInputStream(dis)) { while (true) { recordId = in.readShort(); @@ -620,7 +622,8 @@ public class VBAMacroReader implements Closeable { if (reserved != reservedByte) { if (throwOnUnexpectedReservedByte) { - throw new IOException("Expected " + Integer.toHexString(reservedByte) + "after name before Unicode name, but found: " + + throw new IOException("Expected " + Integer.toHexString(reservedByte) + + "after name before Unicode name, but found: " + Integer.toHexString(reserved)); } else { return new ASCIIUnicodeStringPair(ascii, reserved); -- 2.39.5