import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
private String getShapesString(XSSFReader.SheetIterator it) {
StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
- it.next();
+ assertNotNull(it.next());
List<XSSFShape> shapes = it.getShapes();
if (shapes != null) {
for (XSSFShape shape : shapes) {
}
}
- /**
- * NPE from XSSFReader$SheetIterator.<init> on XLSX files generated by
- * the openpyxl library
- */
- @Test
- void test58747() throws Exception {
- try (OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("58747.xlsx")) {
- ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
- assertNotNull(strings);
- XSSFReader reader = new XSSFReader(pkg);
- StylesTable styles = reader.getStylesTable();
- assertNotNull(styles);
-
- XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData();
- assertTrue(iter.hasNext());
- iter.next();
-
- assertFalse(iter.hasNext());
- assertEquals("Orders", iter.getSheetName());
- }
- }
+ /**
+ * NPE from XSSFReader$SheetIterator.<init> on XLSX files generated by
+ * the openpyxl library
+ */
+ @Test
+ void test58747() throws Exception {
+ try (OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("58747.xlsx")) {
+ ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
+ assertNotNull(strings);
+ XSSFReader reader = new XSSFReader(pkg);
+ StylesTable styles = reader.getStylesTable();
+ assertNotNull(styles);
+
+ XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData();
+ assertTrue(iter.hasNext());
+ assertNotNull(iter.next());
+
+ assertFalse(iter.hasNext());
+ assertEquals("Orders", iter.getSheetName());
+ }
+ }
/**
* NPE when sheet has no relationship id in the workbook
}
@Disabled("until we fix issue https://bz.apache.org/bugzilla/show_bug.cgi?id=61701")
+ @Test
void test61701() throws Exception {
try(Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("simple-table-named-range.xlsx")) {
Name name = workbook.getName("total");
}
@Test
- void testStrictOoxmlNotAllowed() throws Exception {
+ void testStrictOoxmlNotAllowed() {
assertThrows(POIXMLException.class, () -> {
try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
XSSFReader reader = new XSSFReader(pkg);
+ assertNotNull(reader);
}
});
assertThrows(POIXMLException.class, () -> {
try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
XSSFReader reader = new XSSFReader(pkg, false);
+ assertNotNull(reader);
}
});
}
return Base64.getEncoder().encodeToString(md.digest());
}
+
+ @Test
+ public void testMissingLiteFile() throws IOException, OpenXML4JException {
+ try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream(
+ "clusterfuzz-testcase-minimized-XLSX2CSVFuzzer-6594557414080512.xlsx"))) {
+ XSSFReader xssfReader = new XSSFReader(pkg);
+ assertThrows(IOException.class,
+ xssfReader::getStylesTable,
+ "The file is broken, but triggers loading of some additional resources which would "
+ + "be missing in the ooxml-lite package otherwise.");
+ }
+ }
}