From 5a6df66b07ba527bc4195a604b446af807087c66 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 12 Dec 2022 18:43:44 +0000 Subject: [PATCH] untidy hack for shared string counts that are higher than Integer.MAX_VALUE git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905940 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestReadOnlySharedStringsTable.java | 28 ++++++++++++++++-- test-data/spreadsheet/MalformedSSTCount.xlsx | Bin 0 -> 6266 bytes 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/MalformedSSTCount.xlsx diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java index 992dc32113..7df35d713c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java @@ -69,11 +69,35 @@ public final class TestReadOnlySharedStringsTable { } } + @Test + void testParseMalformedCountFile() throws Exception { + try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("MalformedSSTCount.xlsx"))) { + List parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); + assertEquals(1, parts.size()); + + SharedStringsTable stbl = new SharedStringsTable(parts.get(0)); + ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0)); + ReadOnlySharedStringsTable rtbl2; + try (InputStream stream = parts.get(0).getInputStream()) { + rtbl2 = new ReadOnlySharedStringsTable(stream); + } + + assertEquals(stbl.getCount(), rtbl.getCount()); + assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount()); + assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount()); + for (int i = 0; i < stbl.getUniqueCount(); i++) { + RichTextString i1 = stbl.getItemAt(i); + assertEquals(i1.getString(), rtbl.getItemAt(i).getString()); + assertEquals(i1.getString(), rtbl2.getItemAt(i).getString()); + } + } + } + //51519 @Test void testPhoneticRuns() throws Exception { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("51519.xlsx"))) { - List < PackagePart > parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); + List parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); assertEquals(1, parts.size()); ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0), true); @@ -83,7 +107,7 @@ public final class TestReadOnlySharedStringsTable { assertEquals("\u65E5\u672C\u30AA\u30E9\u30AF\u30EB \u30CB\u30DB\u30F3", rtbl.getItemAt(3).getString()); //now do not include phonetic runs - rtbl = new ReadOnlySharedStringsTable(parts.get(0),false); + rtbl = new ReadOnlySharedStringsTable(parts.get(0), false); assertEquals(49, rtbl.getUniqueCount()); assertEquals("\u30B3\u30E1\u30F3\u30C8", rtbl.getItemAt(0).getString()); diff --git a/test-data/spreadsheet/MalformedSSTCount.xlsx b/test-data/spreadsheet/MalformedSSTCount.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..6c955fa684d22022389002f67d41358a0037854c GIT binary patch literal 6266 zcmbVQ2RxOJ8b0|L@~wv$;_ zxW2mn(bfHR@B96}Gk@p#-t#{1_q;<>1p|`|gnM{AbM(;#{oC}hKp;{O1ISnw=HzDW z1^$4!hOflL05+mgd-yp3I)!$rlHW=cfcSt%sC7Y=*L5~&Si}TUdZS!$N2&_ z_f|iM@}U2F+ypiO{?!Y7QS`4ydiLQR>^i!5>|tTeua;{bX}AjwyDz?`MXB6G&LZq&>WA)(G&H8^Q?j2>yk$j;OvI$vy@TH)2C%Ng1ca^nF@ z^n0cxIR`1{CXFc>YV2b8Kl(iA_0Uwo!HxMgEo6uW0s;JJ{$LIujMC>9bHICyL+0){ z@cdxvidiUB_V5Ire`D$=!0*&M9TG|W6Tk!JVs8n9*`J^tbx8Rsv`1+-I}Pzds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