add negative test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1919065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2024-07-09 14:43:03 +00:00
parent bfd4645a72
commit 302b43641f
3 changed files with 14 additions and 0 deletions

View 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",

View 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 {

Binary file not shown.