aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Allison <tallison@apache.org>2018-10-26 19:06:18 +0000
committerTim Allison <tallison@apache.org>2018-10-26 19:06:18 +0000
commitaf9142e4b744638fa448f81081a7cda1bc376576 (patch)
tree7d4f3b0b7cfe9ad62a28fd51f544bb05364ab965
parent960cbb77146c550661c7f75ef86a151c0f4528d5 (diff)
downloadpoi-af9142e4b744638fa448f81081a7cda1bc376576.tar.gz
poi-af9142e4b744638fa448f81081a7cda1bc376576.zip
bug 62859 -- fix two potential NPEs when initializing XWPFSDTContent
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1844920 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java6
-rw-r--r--src/ooxml/testcases/org/apache/poi/sl/TestFonts.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java13
-rw-r--r--test-data/document/Bug62859.docxbin0 -> 17326 bytes
4 files changed, 20 insertions, 1 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
index 99ab66a7ee..f39c5cf482 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
@@ -47,6 +47,9 @@ public class XWPFSDTContent implements ISDTContent {
private List<ISDTContents> bodyElements = new ArrayList<>();
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
+ if (sdtRun == null) {
+ return;
+ }
for (CTR ctr : sdtRun.getRArray()) {
XWPFRun run = new XWPFRun(ctr, parent);
// runs.add(run);
@@ -55,6 +58,9 @@ public class XWPFSDTContent implements ISDTContent {
}
public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
+ if (block == null) {
+ return;
+ }
XmlCursor cursor = block.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java b/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java
index b7a6d16a54..f35065de75 100644
--- a/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java
+++ b/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java
@@ -74,7 +74,7 @@ public class TestFonts {
// currently linux and mac return quite different values
private static final int[] expected_sizes = {
304, // windows 10, 1080p, MS Office 2016, system text scaling 100% instead of default 125%
- 306, // Windows 10, 15.6" 3840x2160
+ 306, 308,// Windows 10, 15.6" 3840x2160
311, 312, 313, 318,
348, // Windows 10, 15.6" 3840x2160
362, // Windows 10, 13.3" 1080p high-dpi
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
index deac5c09ae..9388e08710 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
@@ -148,6 +148,19 @@ public final class TestXWPFSDT {
assertEquals("", sdts.get(0).getTitle());
}
+ @Test
+ public void test62859() throws IOException {
+ //this doesn't test the exact code path for this issue, but
+ //it does test for a related issue, and the fix fixes both.
+ //We should try to add the actual triggering document
+ //to our test suite.
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug62859.docx");
+ List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+ assertEquals(1, sdts.size());
+ assertEquals("", sdts.get(0).getTag());
+ assertEquals("", sdts.get(0).getTitle());
+ }
+
private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
List<XWPFAbstractSDT> sdts = new ArrayList<>();
diff --git a/test-data/document/Bug62859.docx b/test-data/document/Bug62859.docx
new file mode 100644
index 0000000000..e0ede4a83d
--- /dev/null
+++ b/test-data/document/Bug62859.docx
Binary files differ