From a42842841e58e779cdabc5f418aefd4d14254817 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 7 Oct 2023 22:12:12 +0000 Subject: [PATCH] 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 --- poi-ooxml-lite/missing-xsbs.txt | 1 + .../xssf/eventusermodel/TestXSSFReader.java | 62 ++++++++++++------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/poi-ooxml-lite/missing-xsbs.txt b/poi-ooxml-lite/missing-xsbs.txt index ccd8fd159df..ee55b0f7962 100644 --- a/poi-ooxml-lite/missing-xsbs.txt +++ b/poi-ooxml-lite/missing-xsbs.txt @@ -98,6 +98,7 @@ ctwraptightae95type ctwraptopbottom5e13type lockedcanvaselement polylineelement +relationships93b3doctype relidselement stalignh768ctype stalignv5abetype diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java index 8dd8a70e238..cec4181569c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java @@ -34,6 +34,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more 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; @@ -226,7 +227,7 @@ void testShapes() throws Exception { private String getShapesString(XSSFReader.SheetIterator it) { StringBuilder sb = new StringBuilder(); while (it.hasNext()) { - it.next(); + assertNotNull(it.next()); List shapes = it.getShapes(); if (shapes != null) { for (XSSFShape shape : shapes) { @@ -259,27 +260,27 @@ void testBug57914() throws Exception { } } - /** - * NPE from XSSFReader$SheetIterator. 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. 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 @@ -329,6 +330,7 @@ void test61034() throws Exception { } @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"); @@ -353,15 +355,17 @@ void test66612() throws Exception { } @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); } }); } @@ -435,4 +439,16 @@ private static String hash(XSSFReader reader) throws IOException { 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."); + } + } }