From d4bcc2b3bbcd9d7dafe9d46c126c9d0e1ddfcdd8 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 20 Apr 2024 07:53:40 +0000 Subject: Bug 66425: Avoid exceptions found via poi-fuzz Prevent a NullPointerException Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65448 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917175 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xwpf/usermodel/XWPFFootnotes.java | 7 +++++-- ...stcase-minimized-POIXWPFFuzzer-5166796835258368.docx | Bin 0 -> 12890 bytes 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test-data/document/clusterfuzz-testcase-minimized-POIXWPFFuzzer-5166796835258368.docx diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java index f9bdfb7ad8..177a570882 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java @@ -127,8 +127,11 @@ public class XWPFFootnotes extends XWPFAbstractFootnotesEndnotes { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes")); PackagePart part = getPackagePart(); - try (OutputStream out = part.getOutputStream()) { - ctFootnotes.save(out, xmlOptions); + + if (ctFootnotes != null) { + try (OutputStream out = part.getOutputStream()) { + ctFootnotes.save(out, xmlOptions); + } } } diff --git a/test-data/document/clusterfuzz-testcase-minimized-POIXWPFFuzzer-5166796835258368.docx b/test-data/document/clusterfuzz-testcase-minimized-POIXWPFFuzzer-5166796835258368.docx new file mode 100644 index 0000000000..08e62e49e2 Binary files /dev/null and b/test-data/document/clusterfuzz-testcase-minimized-POIXWPFFuzzer-5166796835258368.docx differ -- cgit v1.2.3