bug 59830: add context to why no more bytes could be read from input stream

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-09 05:39:56 +00:00
parent a6f5ef09ef
commit 909c07f37f
3 changed files with 36 additions and 14 deletions

View 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;
}
}

View 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 {

View File

@ -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<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();
}
}