]> source.dussan.org Git - poi.git/commitdiff
add negative test
authorPJ Fanning <fanningpj@apache.org>
Tue, 9 Jul 2024 14:43:03 +0000 (14:43 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 9 Jul 2024 14:43:03 +0000 (14:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1919065 13f79535-47bb-0310-9956-ffa450edef68

poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
test-data/document/unicode-path.docx [new file with mode: 0644]

index fafbab4195255636d5ffa739d73c776d1514c410..2f8ba9aafa17807aafa6b9e6878dc02567535ca6 100644 (file)
@@ -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",
index 0546e7cd11b511abedc4e73ba7468c0bb10f2ad9..36c30a7428d8e42bae729628f81abe1749e2c1b7 100644 (file)
@@ -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;
@@ -504,6 +505,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 {
diff --git a/test-data/document/unicode-path.docx b/test-data/document/unicode-path.docx
new file mode 100644 (file)
index 0000000..1855aa1
Binary files /dev/null and b/test-data/document/unicode-path.docx differ