aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-07-20 14:03:35 +0000
committerDominik Stadler <centic@apache.org>2015-07-20 14:03:35 +0000
commitdbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56 (patch)
treec5590ee35e758e7a57facbe27d2bce57414f0406 /src/testcases/org
parentee3925aff1996f68442ae366feff4cd30d525c21 (diff)
downloadpoi-dbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56.tar.gz
poi-dbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56.zip
Bug 58156: Possible data corruption in hasPOIFSHeader and hasOOXMLHeader
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691948 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
index d475b7aad0..d5d92bd6bb 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
@@ -17,12 +17,16 @@
package org.apache.poi.poifs.filesystem;
-import junit.framework.TestCase;
-
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.util.Arrays;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import junit.framework.TestCase;
+
/**
* Class to test that POIFS complains when given an Office 2007 XML document
*
@@ -38,7 +42,7 @@ public class TestOffice2007XMLException extends TestCase {
InputStream in = openSampleStream("sample.xlsx");
try {
- new POIFSFileSystem(in);
+ new POIFSFileSystem(in).close();
fail("expected exception was not thrown");
} catch(OfficeXmlFileException e) {
// expected during successful test
@@ -72,4 +76,39 @@ public class TestOffice2007XMLException extends TestCase {
in.close();
}
}
+
+ public void testFileCorruption() throws Exception {
+
+ // create test InputStream
+ byte[] testData = { (byte)1, (byte)2, (byte)3 };
+ InputStream testInput = new ByteArrayInputStream(testData);
+
+ // detect header
+ InputStream in = new PushbackInputStream(testInput, 10);
+ assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+
+ // check if InputStream is still intact
+ byte[] test = new byte[3];
+ in.read(test);
+ assertTrue(Arrays.equals(testData, test));
+ assertEquals(-1, in.read());
+ }
+
+
+ public void testFileCorruptionOPOIFS() throws Exception {
+
+ // create test InputStream
+ byte[] testData = { (byte)1, (byte)2, (byte)3 };
+ InputStream testInput = new ByteArrayInputStream(testData);
+
+ // detect header
+ InputStream in = new PushbackInputStream(testInput, 10);
+ assertFalse(OPOIFSFileSystem.hasPOIFSHeader(in));
+
+ // check if InputStream is still intact
+ byte[] test = new byte[3];
+ in.read(test);
+ assertTrue(Arrays.equals(testData, test));
+ assertEquals(-1, in.read());
+ }
}