]> source.dussan.org Git - poi.git/commitdiff
bug 59830: add context to why no more bytes could be read from input stream
authorJaven O'Neal <onealj@apache.org>
Sat, 9 Jul 2016 05:39:56 +0000 (05:39 +0000)
committerJaven O'Neal <onealj@apache.org>
Sat, 9 Jul 2016 05:39:56 +0000 (05:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751982 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
src/java/org/apache/poi/util/RLEDecompressingInputStream.java
src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java

index d50a2501546a27e5b347fae50b206fc349fee664..260712ad12b4e0907855c93f5d506d47e89dbebb 100644 (file)
@@ -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;
                         }
                     }
index de18fee36c7dd2bc389459e242e59b91e46e3f4d..8d826eb12bc76518113bdc14aee6b4b6f3ca8ea7 100644 (file)
@@ -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 {
index 2f2feee07298e839f94aac36672ffc2c8d1b1a33..4d844a6db731662127851a524333f194b20f0420 100644 (file)
 
 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<POIDataSamples, String> 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<String, String> macros = reader.readMacros();
+        assertNotNull(macros);
+        reader.close();
+    }
 }