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

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61249

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2023-08-07 09:42:17 +00:00
parent 6f054ddce1
commit 31fd087a48
3 changed files with 45 additions and 41 deletions

View File

@ -241,6 +241,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
for (RelationPart rp : getRelationParts()) { for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart(); POIXMLDocumentPart p = rp.getDocumentPart();
String relation = rp.getRelationship().getRelationshipType(); String relation = rp.getRelationship().getRelationshipType();
try {
if (relation.equals(XWPFRelation.STYLES.getRelation())) { if (relation.equals(XWPFRelation.STYLES.getRelation())) {
this.styles = (XWPFStyles) p; this.styles = (XWPFStyles) p;
this.styles.onDocumentRead(); this.styles.onDocumentRead();
@ -284,6 +285,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
POIXMLDocumentPart._invokeOnDocumentRead(gp); 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(); initHyperlinks();
} catch (XmlException e) { } catch (XmlException e) {

Binary file not shown.