diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 09d6a6eefe..1ddc55d98a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -241,48 +241,52 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { for (RelationPart rp : getRelationParts()) { POIXMLDocumentPart p = rp.getDocumentPart(); String relation = rp.getRelationship().getRelationshipType(); - if (relation.equals(XWPFRelation.STYLES.getRelation())) { - this.styles = (XWPFStyles) p; - this.styles.onDocumentRead(); - } else if (relation.equals(XWPFRelation.THEME.getRelation())) { - this.theme = (XWPFTheme) p; - this.theme.onDocumentRead(); - } else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) { - this.numbering = (XWPFNumbering) p; - this.numbering.onDocumentRead(); - } else if (relation.equals(XWPFRelation.FOOTER.getRelation())) { - XWPFFooter footer = (XWPFFooter) p; - footers.add(footer); - footer.onDocumentRead(); - } else if (relation.equals(XWPFRelation.HEADER.getRelation())) { - XWPFHeader header = (XWPFHeader) p; - headers.add(header); - header.onDocumentRead(); - } else if (relation.equals(XWPFRelation.COMMENT.getRelation())) { - this.comments = (XWPFComments) p; - this.comments.onDocumentRead(); - } else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) { - settings = (XWPFSettings) p; - settings.onDocumentRead(); - } else if (relation.equals(XWPFRelation.IMAGES.getRelation())) { - XWPFPictureData picData = (XWPFPictureData) p; - picData.onDocumentRead(); - registerPackagePictureData(picData); - pictures.add(picData); - } else if (relation.equals(XWPFRelation.CHART.getRelation())) { - //now we can use all methods to modify charts in XWPFDocument - XWPFChart chartData = (XWPFChart) p; - charts.add(chartData); - } else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) { - // We don't currently process the glossary itself - // Until we do, we do need to load the glossary child parts of it - for (POIXMLDocumentPart gp : p.getRelations()) { - // Trigger the onDocumentRead for all the child parts - // Otherwise we'll hit issues on Styles, Settings etc on save - // TODO: Refactor this to not need to access protected method - // from other package! Remove the static helper method once fixed!!! - POIXMLDocumentPart._invokeOnDocumentRead(gp); + try { + if (relation.equals(XWPFRelation.STYLES.getRelation())) { + this.styles = (XWPFStyles) p; + this.styles.onDocumentRead(); + } else if (relation.equals(XWPFRelation.THEME.getRelation())) { + this.theme = (XWPFTheme) p; + this.theme.onDocumentRead(); + } else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) { + this.numbering = (XWPFNumbering) p; + this.numbering.onDocumentRead(); + } else if (relation.equals(XWPFRelation.FOOTER.getRelation())) { + XWPFFooter footer = (XWPFFooter) p; + footers.add(footer); + footer.onDocumentRead(); + } else if (relation.equals(XWPFRelation.HEADER.getRelation())) { + XWPFHeader header = (XWPFHeader) p; + headers.add(header); + header.onDocumentRead(); + } else if (relation.equals(XWPFRelation.COMMENT.getRelation())) { + this.comments = (XWPFComments) p; + this.comments.onDocumentRead(); + } else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) { + settings = (XWPFSettings) p; + settings.onDocumentRead(); + } else if (relation.equals(XWPFRelation.IMAGES.getRelation())) { + XWPFPictureData picData = (XWPFPictureData) p; + picData.onDocumentRead(); + registerPackagePictureData(picData); + pictures.add(picData); + } else if (relation.equals(XWPFRelation.CHART.getRelation())) { + //now we can use all methods to modify charts in XWPFDocument + XWPFChart chartData = (XWPFChart) p; + charts.add(chartData); + } else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) { + // We don't currently process the glossary itself + // Until we do, we do need to load the glossary child parts of it + for (POIXMLDocumentPart gp : p.getRelations()) { + // Trigger the onDocumentRead for all the child parts + // Otherwise we'll hit issues on Styles, Settings etc on save + // TODO: Refactor this to not need to access protected method + // from other package! Remove the static helper method once fixed!!! + POIXMLDocumentPart._invokeOnDocumentRead(gp); + } } + } catch (ClassCastException e) { + throw new IllegalArgumentException("Relation and type of document-part did not match, had relation " + relation + " and type of document-part: " + p.getClass()); } } initHyperlinks(); diff --git a/test-data/document/clusterfuzz-testcase-minimized-POIFuzzer-6709287337197568.docx b/test-data/document/clusterfuzz-testcase-minimized-POIFuzzer-6709287337197568.docx new file mode 100644 index 0000000000..ff963e1ebb Binary files /dev/null and b/test-data/document/clusterfuzz-testcase-minimized-POIFuzzer-6709287337197568.docx differ diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls index 6ad5da595b..74b0f1b5da 100644 Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ