aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-09-07 08:35:23 +0000
committerDominik Stadler <centic@apache.org>2023-09-07 08:35:23 +0000
commit5c2a89412b08c4b71f2ab79b88f26827028916b4 (patch)
treedce06f37593cf843170e3f2c39fab73ae4d30a6b /poi-ooxml/src
parent40cdc76f6361f65cd2fa9f9eeade4825f92d5efc (diff)
downloadpoi-5c2a89412b08c4b71f2ab79b88f26827028916b4.tar.gz
poi-5c2a89412b08c4b71f2ab79b88f26827028916b4.zip
Bug 66425: Avoid a ClassCastException found via oss-fuzz
We try to avoid throwing ClassCastException, but it was possible to trigger one here with a specially crafted input-file Fixes https://oss-fuzz.com/testcase-detail/4959857092198400 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java8
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java8
2 files changed, 12 insertions, 4 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
index 84a02e10f7..225a8f496e 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
@@ -71,11 +71,11 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
*/
public XWPFHeaderFooter(POIXMLDocumentPart parent, PackagePart part) {
super(parent, part);
- this.document = (XWPFDocument) getParent();
-
- if (this.document == null) {
- throw new NullPointerException();
+ final POIXMLDocumentPart p = getParent();
+ if (!(p instanceof XWPFDocument)) {
+ throw new IllegalArgumentException("Had unexpected type of parent: " + (p == null ? "<null>" : p.getClass()));
}
+ this.document = (XWPFDocument) p;
}
@Override
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
index 074a941669..83ed6c11f1 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
@@ -271,4 +271,12 @@ public final class XWPFRelation extends POIXMLRelation {
return _table.get(rel);
}
+ @Override
+ public String toString() {
+ return "XWPFRelation{" +
+ //getRelation() + "/" +
+ getContentType() + "/" +
+ getDefaultFileName() +
+ "}";
+ }
}