]> source.dussan.org Git - poi.git/commitdiff
60293 -- Handle illegal "Odd" header/footer in XWPF
authorTim Allison <tallison@apache.org>
Mon, 31 Oct 2016 19:02:06 +0000 (19:02 +0000)
committerTim Allison <tallison@apache.org>
Mon, 31 Oct 2016 19:02:06 +0000 (19:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1767353 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
test-data/document/60293.docx [new file with mode: 0644]

index 8ff59713af45441d0a8b3ae3ce7aace7fc8e0422..682b1cfd48aab3c532892e57eb8d84737d25417f 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.poi.xwpf.usermodel.XWPFHeader;
 import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
 import org.apache.poi.xwpf.usermodel.XWPFRelation;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
@@ -115,8 +116,14 @@ public class XWPFHeaderFooterPolicy {
             if (relatedPart != null && relatedPart instanceof XWPFHeader) {
                 hdr = (XWPFHeader) relatedPart;
             }
-            // Assign it
-            Enum type = ref.getType();
+            // Assign it; treat invalid options as "default" POI-60293
+            Enum type;
+            try {
+                type = ref.getType();
+            } catch (XmlValueOutOfRangeException e) {
+                type = STHdrFtr.DEFAULT;
+            }
+
             assignHeader(hdr, type);
         }
         for (int i = 0; i < sectPr.sizeOfFooterReferenceArray(); i++) {
@@ -127,8 +134,13 @@ public class XWPFHeaderFooterPolicy {
             if (relatedPart != null && relatedPart instanceof XWPFFooter) {
                 ftr = (XWPFFooter) relatedPart;
             }
-            // Assign it
-            Enum type = ref.getType();
+            // Assign it; treat invalid options as "default" POI-60293
+            Enum type;
+            try {
+                type = ref.getType();
+            } catch (XmlValueOutOfRangeException e) {
+                type = STHdrFtr.DEFAULT;
+            }
             assignFooter(ftr, type);
         }
     }
index 371c9da0645da10993d85db677229822c283bae5..fbb24f5062025b6042d9a65c260db8d3b8e57c7c 100644 (file)
@@ -220,4 +220,11 @@ public final class TestXWPFHeader {
     public void testGetPictureDataById() {
         // TODO
     }
+
+    @Test
+    public void bug60293() throws Exception {
+        //test handling of non-standard header/footer options
+        XWPFDocument xwpf = XWPFTestDataSamples.openSampleDocument("60293.docx");
+        assertEquals(3, xwpf.getHeaderList().size());
+    }
 }
diff --git a/test-data/document/60293.docx b/test-data/document/60293.docx
new file mode 100644 (file)
index 0000000..02dcabc
Binary files /dev/null and b/test-data/document/60293.docx differ