60293 -- Handle illegal "Odd" header/footer in XWPF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1767353 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2016-10-31 19:02:06 +00:00
parent 14babbb970
commit 2633894b39
3 changed files with 23 additions and 4 deletions

View 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.XWPFHeaderFooter;
import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRelation; 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.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
@ -115,8 +116,14 @@ public class XWPFHeaderFooterPolicy {
if (relatedPart != null && relatedPart instanceof XWPFHeader) { if (relatedPart != null && relatedPart instanceof XWPFHeader) {
hdr = (XWPFHeader) relatedPart; hdr = (XWPFHeader) relatedPart;
} }
// Assign it // Assign it; treat invalid options as "default" POI-60293
Enum type = ref.getType(); Enum type;
try {
type = ref.getType();
} catch (XmlValueOutOfRangeException e) {
type = STHdrFtr.DEFAULT;
}
assignHeader(hdr, type); assignHeader(hdr, type);
} }
for (int i = 0; i < sectPr.sizeOfFooterReferenceArray(); i++) { for (int i = 0; i < sectPr.sizeOfFooterReferenceArray(); i++) {
@ -127,8 +134,13 @@ public class XWPFHeaderFooterPolicy {
if (relatedPart != null && relatedPart instanceof XWPFFooter) { if (relatedPart != null && relatedPart instanceof XWPFFooter) {
ftr = (XWPFFooter) relatedPart; ftr = (XWPFFooter) relatedPart;
} }
// Assign it // Assign it; treat invalid options as "default" POI-60293
Enum type = ref.getType(); Enum type;
try {
type = ref.getType();
} catch (XmlValueOutOfRangeException e) {
type = STHdrFtr.DEFAULT;
}
assignFooter(ftr, type); assignFooter(ftr, type);
} }
} }

View File

@ -220,4 +220,11 @@ public final class TestXWPFHeader {
public void testGetPictureDataById() { public void testGetPictureDataById() {
// TODO // 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());
}
} }

Binary file not shown.