You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2018/04/02 17:15:42 UTC
svn commit: r1828176 - in /poi/trunk: src/integrationtest/org/apache/poi/
src/integrationtest/org/apache/poi/stress/
src/java/org/apache/poi/poifs/filesystem/
src/java/org/apache/poi/poifs/storage/
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel...
Author: centic
Date: Mon Apr 2 17:15:42 2018
New Revision: 1828176
URL: http://svn.apache.org/viewvc?rev=1828176&view=rev
Log:
Bug 61267: detect Word v2 files and report that they are not supported in Apache POI
Added:
poi/trunk/test-data/document/word2.doc
Modified:
poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
poi/trunk/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/FileMagic.java
poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlock.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java
Modified: poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java?rev=1828176&r1=1828175&r2=1828176&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java Mon Apr 2 17:15:42 2018
@@ -302,6 +302,8 @@ public class TestAllFiles {
"spreadsheet/poc-xmlbomb.xlsx", // contains xml-entity-expansion
"spreadsheet/poc-xmlbomb-empty.xlsx", // contains xml-entity-expansion
"spreadsheet/poc-shared-strings.xlsx", // contains shared-string-entity-expansion
+ "document/61612a.docx",
+ "document/word2.doc",
// old Excel files, which we only support simple text extraction of
"spreadsheet/testEXCEL_2.xls",
Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java?rev=1828176&r1=1828175&r2=1828176&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java Mon Apr 2 17:15:42 2018
@@ -54,7 +54,8 @@ public class HPSFFileHandler extends POI
"spreadsheet/55982.xls",
"spreadsheet/testEXCEL_3.xls",
"spreadsheet/testEXCEL_4.xls",
- "hpsf/Test_Humor-Generation.ppt"
+ "hpsf/Test_Humor-Generation.ppt",
+ "document/word2.doc"
);
static final Set<String> EXCLUDES_HANDLE_FILE = unmodifiableHashSet(
Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/FileMagic.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/FileMagic.java?rev=1828176&r1=1828175&r2=1828176&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/FileMagic.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/FileMagic.java Mon Apr 2 17:15:42 2018
@@ -77,10 +77,11 @@ public enum FileMagic {
PDF("%PDF"),
/** Some different HTML documents */
HTML("<!DOCTYP".getBytes(UTF_8), "<html".getBytes(UTF_8)),
+ WORD2(new byte[]{ (byte)0xdb, (byte)0xa5, 0x2d, 0x00}),
// keep UNKNOWN always as last enum!
/** UNKNOWN magic */
UNKNOWN(new byte[0]);
-
+
final byte[][] magic;
FileMagic(long magic) {
Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlock.java?rev=1828176&r1=1828175&r2=1828176&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlock.java Mon Apr 2 17:15:42 2018
@@ -136,6 +136,9 @@ public final class HeaderBlock implement
case MSWRITE:
throw new NotOLE2FileException("The supplied data appears to be in the old MS Write format. "
+ "Apache POI doesn't currently support this format");
+ case WORD2:
+ throw new NotOLE2FileException("The supplied data appears to be an old Word version 2 file. "
+ + "Apache POI doesn't currently support this format");
case BIFF2:
case BIFF3:
case BIFF4:
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java?rev=1828176&r1=1828175&r2=1828176&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java Mon Apr 2 17:15:42 2018
@@ -44,7 +44,7 @@ public final class TestHWPFOldDocument e
// Can't open as HWPFDocument
HWPFTestDataSamples.openSampleFile("Word6.doc");
}
-
+
@Test
public void testWord6hwpfOld() throws IOException {
// Open
@@ -60,8 +60,21 @@ public final class TestHWPFOldDocument e
doc.close();
}
-
-
+ /**
+ * Test a simple Word 2 document
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void testWord2hwpf() throws IOException {
+ // Can't open as HWPFDocument
+ HWPFTestDataSamples.openSampleFile("word2.doc");
+ }
+
+ @Test(expected=RuntimeException.class)
+ public void testWord2hwpfOld() throws IOException {
+ // Open
+ HWPFTestDataSamples.openOldSampleFile("word2.doc");
+ }
+
/**
* Test a simple Word 95 document
*/
Added: poi/trunk/test-data/document/word2.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/word2.doc?rev=1828176&view=auto
==============================================================================
Binary files poi/trunk/test-data/document/word2.doc (added) and poi/trunk/test-data/document/word2.doc Mon Apr 2 17:15:42 2018 differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org