diff --git a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java index d50a25015..260712ad1 100644 --- a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java +++ b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java @@ -238,7 +238,11 @@ public class VBAMacroReader implements Closeable { } break; default: - trySkip(in, len); + try { + trySkip(in, len); + } catch (final IOException e) { + throw new IOException("Error occurred while reading section id " + id, e); + } break; } } diff --git a/src/java/org/apache/poi/util/RLEDecompressingInputStream.java b/src/java/org/apache/poi/util/RLEDecompressingInputStream.java index de18fee36..8d826eb12 100644 --- a/src/java/org/apache/poi/util/RLEDecompressingInputStream.java +++ b/src/java/org/apache/poi/util/RLEDecompressingInputStream.java @@ -230,7 +230,7 @@ public class RLEDecompressingInputStream extends InputStream { /** * Convenience method for read a 2-bytes short in little endian encoding. * - * @return short value from the stream + * @return short value from the stream, -1 if end of stream is reached * @throws IOException */ public int readShort() throws IOException { @@ -240,7 +240,7 @@ public class RLEDecompressingInputStream extends InputStream { /** * Convenience method for read a 4-bytes int in little endian encoding. * - * @return integer value from the stream + * @return integer value from the stream, -1 if end of stream is reached * @throws IOException */ public int readInt() throws IOException { diff --git a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java index 2f2feee07..4d844a6db 100644 --- a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java +++ b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java @@ -17,12 +17,9 @@ package org.apache.poi.poifs.macros; -import org.apache.poi.POIDataSamples; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; -import org.apache.poi.util.IOUtils; -import org.apache.poi.util.StringUtil; -import org.junit.Ignore; -import org.junit.Test; +import static org.apache.poi.POITestCase.assertContains; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.FileInputStream; @@ -32,9 +29,12 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import static org.apache.poi.POITestCase.assertContains; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import org.apache.poi.POIDataSamples; +import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.util.IOUtils; +import org.apache.poi.util.StringUtil; +import org.junit.Ignore; +import org.junit.Test; public class TestVBAMacroReader { private static final Map expectedMacroContents; @@ -178,7 +178,7 @@ public class TestVBAMacroReader { } } - protected void fromStream(POIDataSamples dataSamples, String filename) throws IOException { + protected void fromStream(POIDataSamples dataSamples, String filename) throws IOException { InputStream fis = dataSamples.openResourceAsStream(filename); try { VBAMacroReader r = new VBAMacroReader(fis); @@ -192,7 +192,7 @@ public class TestVBAMacroReader { } } - protected void fromNPOIFS(POIDataSamples dataSamples, String filename) throws IOException { + protected void fromNPOIFS(POIDataSamples dataSamples, String filename) throws IOException { File f = dataSamples.getFile(filename); NPOIFSFileSystem fs = new NPOIFSFileSystem(f); try { @@ -241,4 +241,22 @@ public class TestVBAMacroReader { String testMacroNoSub = expectedMacroContents.get(samples); assertContains(content, testMacroNoSub); } + + @Ignore + @Test + public void bug59830() throws IOException { + // This file is intentionally omitted from the test-data directory + // unless we can extract the vbaProject.bin from this Word 97-2003 file + // so that it's less likely to be opened and executed on a Windows computer. + // The file is attached to bug 59830. + // The Macro Virus only affects Windows computers, as it makes a + // subprocess call to powershell.exe with an encoded payload + // The document contains macros that execute on workbook open if macros + // are enabled + File doc = POIDataSamples.getDocumentInstance().getFile("macro_virus.doc.do_not_open"); + VBAMacroReader reader = new VBAMacroReader(doc); + Map macros = reader.readMacros(); + assertNotNull(macros); + reader.close(); + } }