Add some missing schema-files to ooxml-lite

This should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62255

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912791 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2023-10-07 22:12:12 +00:00
parent 42651f6eda
commit a42842841e
2 changed files with 38 additions and 21 deletions

View File

@ -98,6 +98,7 @@ ctwraptightae95type
ctwraptopbottom5e13type ctwraptopbottom5e13type
lockedcanvaselement lockedcanvaselement
polylineelement polylineelement
relationships93b3doctype
relidselement relidselement
stalignh768ctype stalignh768ctype
stalignv5abetype stalignv5abetype

View File

@ -34,6 +34,7 @@ import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 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.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.HashAlgorithm;
@ -226,7 +227,7 @@ public final class TestXSSFReader {
private String getShapesString(XSSFReader.SheetIterator it) { private String getShapesString(XSSFReader.SheetIterator it) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while (it.hasNext()) { while (it.hasNext()) {
it.next(); assertNotNull(it.next());
List<XSSFShape> shapes = it.getShapes(); List<XSSFShape> shapes = it.getShapes();
if (shapes != null) { if (shapes != null) {
for (XSSFShape shape : shapes) { for (XSSFShape shape : shapes) {
@ -259,27 +260,27 @@ public final class TestXSSFReader {
} }
} }
/** /**
* NPE from XSSFReader$SheetIterator.<init> on XLSX files generated by * NPE from XSSFReader$SheetIterator.<init> on XLSX files generated by
* the openpyxl library * the openpyxl library
*/ */
@Test @Test
void test58747() throws Exception { void test58747() throws Exception {
try (OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("58747.xlsx")) { try (OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("58747.xlsx")) {
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg); ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
assertNotNull(strings); assertNotNull(strings);
XSSFReader reader = new XSSFReader(pkg); XSSFReader reader = new XSSFReader(pkg);
StylesTable styles = reader.getStylesTable(); StylesTable styles = reader.getStylesTable();
assertNotNull(styles); assertNotNull(styles);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData();
assertTrue(iter.hasNext()); assertTrue(iter.hasNext());
iter.next(); assertNotNull(iter.next());
assertFalse(iter.hasNext()); assertFalse(iter.hasNext());
assertEquals("Orders", iter.getSheetName()); assertEquals("Orders", iter.getSheetName());
} }
} }
/** /**
* NPE when sheet has no relationship id in the workbook * NPE when sheet has no relationship id in the workbook
@ -329,6 +330,7 @@ public final class TestXSSFReader {
} }
@Disabled("until we fix issue https://bz.apache.org/bugzilla/show_bug.cgi?id=61701") @Disabled("until we fix issue https://bz.apache.org/bugzilla/show_bug.cgi?id=61701")
@Test
void test61701() throws Exception { void test61701() throws Exception {
try(Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("simple-table-named-range.xlsx")) { try(Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("simple-table-named-range.xlsx")) {
Name name = workbook.getName("total"); Name name = workbook.getName("total");
@ -353,15 +355,17 @@ public final class TestXSSFReader {
} }
@Test @Test
void testStrictOoxmlNotAllowed() throws Exception { void testStrictOoxmlNotAllowed() {
assertThrows(POIXMLException.class, () -> { assertThrows(POIXMLException.class, () -> {
try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
XSSFReader reader = new XSSFReader(pkg); XSSFReader reader = new XSSFReader(pkg);
assertNotNull(reader);
} }
}); });
assertThrows(POIXMLException.class, () -> { assertThrows(POIXMLException.class, () -> {
try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
XSSFReader reader = new XSSFReader(pkg, false); XSSFReader reader = new XSSFReader(pkg, false);
assertNotNull(reader);
} }
}); });
} }
@ -435,4 +439,16 @@ public final class TestXSSFReader {
return Base64.getEncoder().encodeToString(md.digest()); 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.");
}
}
} }