aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2020-05-16 13:05:53 +0000
committerDominik Stadler <centic@apache.org>2020-05-16 13:05:53 +0000
commitd2ad752e1ca157ce6b4918bbed003c6491d7e651 (patch)
treeae006f833366a3449edfdd54093f40e538b0d4d8
parent5bad2968456a16f395311161543f40b47ae03f5e (diff)
downloadpoi-d2ad752e1ca157ce6b4918bbed003c6491d7e651.tar.gz
poi-d2ad752e1ca157ce6b4918bbed003c6491d7e651.zip
Fix bug 64420: NPE in XSSFReader for files with macro-sheets
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877814 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java5
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java35
-rw-r--r--test-data/spreadsheet/64420.xlsmbin0 -> 10062 bytes
3 files changed, 30 insertions, 10 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
index b239951c43..31e20e58a7 100644
--- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
+++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
@@ -69,10 +69,9 @@ public class XSSFReader {
private static final Set<String> WORKSHEET_RELS =
Collections.unmodifiableSet(new HashSet<>(
- Arrays.asList(new String[]{
- XSSFRelation.WORKSHEET.getRelation(),
+ Arrays.asList(XSSFRelation.WORKSHEET.getRelation(),
XSSFRelation.CHARTSHEET.getRelation(),
- })
+ XSSFRelation.MACRO_SHEET_BIN.getRelation())
));
private static final POILogger LOGGER = POILogFactory.getLogger(XSSFReader.class);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
index 272f0c9974..b7fef07e9b 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
@@ -19,13 +19,18 @@ package org.apache.poi.xssf.eventusermodel;
import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertNotContained;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.InputStream;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLException;
@@ -36,7 +41,6 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.StylesTable;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
import org.junit.Ignore;
@@ -88,8 +92,8 @@ public final class TestXSSFReader {
XSSFReader r = new XSSFReader(pkg);
- assertEquals(11, r.getSharedStringsTable().getItems().size());
- assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
+ assertEquals(11, r.getSharedStringsTable().getSharedStringItems().size());
+ assertEquals("Test spreadsheet", r.getSharedStringsTable().getItemAt(0).toString());
}
}
@@ -173,7 +177,7 @@ public final class TestXSSFReader {
assertEquals(3, count);
}
}
-
+
/**
* Iterating over a workbook with chart sheets in it, using the
* XSSFReader method
@@ -293,7 +297,7 @@ public final class TestXSSFReader {
* bug 61304: Call to XSSFReader.getSheetsData() returns duplicate sheets.
*
* The problem seems to be caused only by those xlsx files which have a specific
- * order of the attributes inside the &lt;sheet&gt; tag of workbook.xml
+ * order of the attributes inside the &lt;sheet&gt; tag of workbook.xml
*
* Example (which causes the problems):
* &lt;sheet name="Sheet6" r:id="rId6" sheetId="4"/&gt;
@@ -325,4 +329,21 @@ public final class TestXSSFReader {
System.out.println("workbook.getName(\"total\").getSheetName() returned: " + name.getSheetName());
}
}
+
+ @Test
+ public void test64420() throws Exception {
+ try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("64420.xlsm"))) {
+ XSSFReader reader = new XSSFReader(pkg);
+
+ Iterator<InputStream> iter = reader.getSheetsData();
+ byte[] data = new byte[4096];
+ while (iter.hasNext()) {
+ InputStream stream = iter.next();
+ assertNotNull(stream);
+ int read = IOUtils.readFully(stream, data);
+ assertTrue(read > 0);
+ stream.close();
+ }
+ }
+ }
}
diff --git a/test-data/spreadsheet/64420.xlsm b/test-data/spreadsheet/64420.xlsm
new file mode 100644
index 0000000000..c71d78a2eb
--- /dev/null
+++ b/test-data/spreadsheet/64420.xlsm
Binary files differ