aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-07-03 20:54:56 +0000
committerPJ Fanning <fanningpj@apache.org>2023-07-03 20:54:56 +0000
commit04442923f32894da8d8496145fed186ab1b4fdc4 (patch)
treed8bd502ed1437bad9281ae6ae9f3f1b39aa4c452
parentcd5d0c3d0712249bd36d4ea461b86b7929694944 (diff)
downloadpoi-04442923f32894da8d8496145fed186ab1b4fdc4.tar.gz
poi-04442923f32894da8d8496145fed186ab1b4fdc4.zip
[bug-62181] try to handle file where shared string loading is happening twice
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910759 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java9
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java10
-rw-r--r--test-data/spreadsheet/bug62181.xlsxbin0 -> 874738 bytes
3 files changed, 18 insertions, 1 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index dd4e5ec406..c48c338e6d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -412,7 +412,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
if (packageReadOnly) {
sharedStringSource = new SharedStringsTable();
} else {
- sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
+ List<PackagePart> matchingParts = getPackagePart().getPackage()
+ .getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
+ if (matchingParts.isEmpty()) {
+ sharedStringSource = (SharedStringsTable)
+ createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
+ } else {
+ sharedStringSource = new SharedStringsTable(matchingParts.get(0));
+ }
}
}
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index d30d4d3abc..d8d36726d0 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -110,6 +110,7 @@ import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.CalculationChain;
+import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
@@ -3854,6 +3855,15 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
}
}
+ @Test
+ void testBug62181() throws Exception {
+ try (XSSFWorkbook wb = openSampleWorkbook("bug62181.xlsx")) {
+ SharedStringsTable sst = wb.getSharedStringSource();
+ assertNotNull(sst);
+ assertEquals(0, sst.getCount());
+ }
+ }
+
private static void readByCommonsCompress(File temp_excel_poi) throws IOException {
/* read by commons-compress*/
try (ZipFile zipFile = new ZipFile(temp_excel_poi)) {
diff --git a/test-data/spreadsheet/bug62181.xlsx b/test-data/spreadsheet/bug62181.xlsx
new file mode 100644
index 0000000000..f0e04126b3
--- /dev/null
+++ b/test-data/spreadsheet/bug62181.xlsx
Binary files differ