aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-07-09 14:43:03 +0000
committerPJ Fanning <fanningpj@apache.org>2024-07-09 14:43:03 +0000
commit302b43641f6329dbf02c8816950dd4c554327288 (patch)
treef38f016d06cc87d2f1d598bac7a36009d09f81fa
parentbfd4645a726c13eef376a5127c8aca4f40f5e8f6 (diff)
downloadpoi-302b43641f6329dbf02c8816950dd4c554327288.tar.gz
poi-302b43641f6329dbf02c8816950dd4c554327288.zip
add negative test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1919065 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java1
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java13
-rw-r--r--test-data/document/unicode-path.docxbin0 -> 5720 bytes
3 files changed, 14 insertions, 0 deletions
diff --git a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
index fafbab4195..2f8ba9aafa 100644
--- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
+++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
@@ -98,6 +98,7 @@ public class TestAllFiles {
"poifs/protected_sha512.xlsx",
// corrupt file
+ "document/unicode-path.docx",
"spreadsheet/duplicate-filename.xlsx",
"spreadsheet/duplicate-filename-case-insensitive.xlsx",
"document/clusterfuzz-testcase-minimized-POIXWPFFuzzer-5166796835258368.docx",
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
index 0546e7cd11..36c30a7428 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
@@ -35,6 +35,7 @@ import java.util.Optional;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.PictureType;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.POIXMLProperties;
import org.apache.poi.ooxml.TrackingInputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -505,6 +506,18 @@ public final class TestXWPFDocument {
}
@Test
+ void testUnicodePathDocWithCorruptZipEntry() {
+ // this is a file that we do not want to be able to parse, as it contains a corrupt zip entry
+ POIXMLException ex = assertThrows(POIXMLException.class, () -> {
+ try (XWPFDocument doc = new XWPFDocument(
+ POIDataSamples.getDocumentInstance().openResourceAsStream("unicode-path.docx"))) {
+ // expect exception here
+ }
+ });
+ assertEquals("InvalidFormatException", ex.getCause().getClass().getSimpleName());
+ }
+
+ @Test
@Disabled("XWPF should be able to write to a new Stream when opened Read-Only")
void testWriteFromReadOnlyOPC() throws Exception {
try (OPCPackage opc = OPCPackage.open(
diff --git a/test-data/document/unicode-path.docx b/test-data/document/unicode-path.docx
new file mode 100644
index 0000000000..1855aa1e74
--- /dev/null
+++ b/test-data/document/unicode-path.docx
Binary files differ