From d2ad752e1ca157ce6b4918bbed003c6491d7e651 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 16 May 2020 13:05:53 +0000 Subject: [PATCH] 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 --- .../poi/xssf/eventusermodel/XSSFReader.java | 5 +-- .../xssf/eventusermodel/TestXSSFReader.java | 35 ++++++++++++++---- test-data/spreadsheet/64420.xlsm | Bin 0 -> 10062 bytes 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 test-data/spreadsheet/64420.xlsm 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 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 <sheet> tag of workbook.xml + * order of the attributes inside the <sheet> tag of workbook.xml * * Example (which causes the problems): * <sheet name="Sheet6" r:id="rId6" sheetId="4"/> @@ -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 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 0000000000000000000000000000000000000000..c71d78a2eb4ebf6b307cc41f7f3563ab1aff7335 GIT binary patch literal 10062 zcmeHN1y>!(*1foEa3{FCbAuDy-QE2XBv^oOad($sK@uRi2Djku2@>3bTlj8f-uq^T znfD9c>t3sS_3A!*byx3Q`_!pYk%xiB0l)(g0RR9cz*axcJpc*-u!REvo&gY{^(CC0 z+%28ljWxVoEJ22>UXBhF1+dWcc>rk0^Z(oai(8;aW6-IK9kWe)Peig^D?Cs_Qxg`Q z1z0arL~e3`6z<|MY;JRXr}Sk~3MWEzk7ntb#s5?xV18OqH>iIoBkR>CbotLR<&0dz z3rm{}ZRSYurb*+oqN7@G9QYgC_ms8J*(qx~vyv$reMVJNR8YQDz(^!_-Ri-?qqv2{~p&c~sLYyJ6(8!i86x1LE$<0_-9S67nhxrg2__M}t-3D`s_D60dy= zVpm0O!fvvO29C%f7Y=;mV(?@ix9P}iV-U@BY(JxfHq!!&4UjSRc)aXxB8jhu{00!R zN2?pqZMnVpfgz5^4Lj3VSl23@AMUO$W|iXmh8C(Ngc@;5fs4ZEL!Af^$~`{9095{> z+d55ls&mL41&AzBAi6bnvvdHlvHm*#Pp|*QBK^~+S0pGZceA5{k7e#d2d-vT;xNVK zJ;h{NC^h`w$Sz~lMZcpaUg@AC!PFoMhItv#=6^r5v?3h6H$Zv0&Rr3SjUz-=?^y{> zy>)$sz)0(sBJEo7tq03v=3?eD{iU2Yy+>OtV|im~zWm@CmGso9WHsg(t2PnRvmz2O z9xy#nuTN2T)$IBM)Qq_LVI{b#fiG__aV#@nE~R)EO(aY};b1ZycK~E&z3{epEXPgoxwo-}!{;-}%#LRdzAQ>v18UE?v9CGDUiQ=ET?FXWa-R-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