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
This commit is contained in:
Dominik Stadler 2020-05-16 13:05:53 +00:00
parent 5bad296845
commit d2ad752e1c
3 changed files with 30 additions and 10 deletions

View File

@ -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);

View File

@ -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();
}
}
}
}

Binary file not shown.