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 = private static final Set<String> WORKSHEET_RELS =
Collections.unmodifiableSet(new HashSet<>( Collections.unmodifiableSet(new HashSet<>(
Arrays.asList(new String[]{ Arrays.asList(XSSFRelation.WORKSHEET.getRelation(),
XSSFRelation.WORKSHEET.getRelation(),
XSSFRelation.CHARTSHEET.getRelation(), XSSFRelation.CHARTSHEET.getRelation(),
}) XSSFRelation.MACRO_SHEET_BIN.getRelation())
)); ));
private static final POILogger LOGGER = POILogFactory.getLogger(XSSFReader.class); 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.assertContains;
import static org.apache.poi.POITestCase.assertNotContained; 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.io.InputStream;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLException; 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.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.StylesTable; 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.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSimpleShape; import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
import org.junit.Ignore; import org.junit.Ignore;
@ -88,8 +92,8 @@ public final class TestXSSFReader {
XSSFReader r = new XSSFReader(pkg); XSSFReader r = new XSSFReader(pkg);
assertEquals(11, r.getSharedStringsTable().getItems().size()); assertEquals(11, r.getSharedStringsTable().getSharedStringItems().size());
assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString()); assertEquals("Test spreadsheet", r.getSharedStringsTable().getItemAt(0).toString());
} }
} }
@ -325,4 +329,21 @@ public final class TestXSSFReader {
System.out.println("workbook.getName(\"total\").getSheetName() returned: " + name.getSheetName()); 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.