Author: tallison
Date: Tue Oct 18 15:47:38 2016
New Revision: 1765468

URL: http://svn.apache.org/viewvc?rev=1765468&view=rev
Log:
BUG 59830 -- incorrect reading of unicode stream name

Added:
    poi/trunk/test-data/spreadsheet/59830.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
    poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java?rev=1765468&r1=1765467&r2=1765468&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java Tue Oct 
18 15:47:38 2016
@@ -29,6 +29,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.zip.ZipEntry;
@@ -268,6 +269,7 @@ public class VBAMacroReader implements C
     private static final int MODULE_NAME = 0x0019;
     private static final int MODULE_NAME_UNICODE = 0x0047;
     private static final int MODULE_DOC_STRING = 0x001c;
+    private static final int STREAMNAME_RESERVED = 0x0032;
 
     /**
      * Reads VBA Project modules from a VBA Project directory located at
@@ -287,6 +289,7 @@ public class VBAMacroReader implements C
                     // process DIR
                     RLEDecompressingInputStream in = new 
RLEDecompressingInputStream(dis);
                     String streamName = null;
+                    String streamNameUnicode = null;
                     int recordId = 0;
                     try {
                         while (true) {
@@ -306,6 +309,14 @@ public class VBAMacroReader implements C
                                 break;
                             case STREAMNAME:
                                 streamName = readString(in, recordLength, 
modules.charset);
+                                int reserved = in.readShort();
+                                if (reserved != STREAMNAME_RESERVED) {
+                                    throw new IOException("Expected x0032 
after stream name before Unicode stream name, but found: "+
+                                            Integer.toHexString(reserved));
+                                }
+                                int unicodeNameRecordLength = in.readInt();
+                                streamNameUnicode = readUnicodeString(in, 
unicodeNameRecordLength);
+                                //do something with this at some point
                                 break;
                             case MODULEOFFSET:
                                 readModule(in, streamName, modules);
@@ -334,4 +345,10 @@ public class VBAMacroReader implements C
             }
         }
     }
+
+    private String readUnicodeString(RLEDecompressingInputStream in, int 
unicodeNameRecordLength) throws IOException {
+        byte[] buffer = new byte[unicodeNameRecordLength];
+        IOUtils.readFully(in, buffer);
+        return new String(buffer, Charset.forName("UTF-16LE"));
+    }
 }

Modified: 
poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java?rev=1765468&r1=1765467&r2=1765468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java 
Tue Oct 18 15:47:38 2016
@@ -244,22 +244,15 @@ public class TestVBAMacroReader {
         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();
+        //test file is "609751.xls" in govdocs1
+        File f = POIDataSamples.getSpreadSheetInstance().getFile("59830.xls");
+        VBAMacroReader r = new VBAMacroReader(f);
+        Map<String, String> macros = r.readMacros();
+        assertNotNull(macros.get("Module20"));
+        assertContains(macros.get("Module20"), "here start of superscripting");
     }
     
     // This test is written as expected-to-fail and should be rewritten

Added: poi/trunk/test-data/spreadsheet/59830.xls
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/59830.xls?rev=1765468&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/59830.xls
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-excel



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to