mirror of https://github.com/apache/poi.git
#62886 - Regression extracting text from corrupted docx files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849252 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5344049a98
commit
6c5a2de640
|
@ -20,6 +20,7 @@ package org.apache.poi.openxml4j.util;
|
|||
import static org.apache.poi.openxml4j.util.ZipSecureFile.MAX_ENTRY_SIZE;
|
||||
import static org.apache.poi.openxml4j.util.ZipSecureFile.MIN_INFLATE_RATIO;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -144,6 +145,8 @@ public class ZipArchiveThresholdInputStream extends FilterInputStream {
|
|||
"No valid entries or contents found, this is not a valid OOXML (Office Open XML) file", ze);
|
||||
}
|
||||
throw ze;
|
||||
} catch (EOFException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,24 @@ import org.junit.Test;
|
|||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
|
||||
|
||||
public class TestXWPFBugs {
|
||||
private static final POIDataSamples samples = POIDataSamples.getDocumentInstance();
|
||||
|
||||
@Test
|
||||
public void truncatedDocx() throws Exception {
|
||||
try (InputStream fis = samples.openResourceAsStream("truncated62886.docx");
|
||||
OPCPackage opc = OPCPackage.open(fis);
|
||||
XWPFWordExtractor ext = new XWPFWordExtractor(opc)) {
|
||||
assertNotNull(ext.getText());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A word document that's encrypted with non-standard
|
||||
* Encryption options, and no cspname section. See bug 53475
|
||||
*/
|
||||
@Test
|
||||
public void bug53475NoCSPName() throws Exception {
|
||||
File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx");
|
||||
File file = samples.getFile("bug53475-password-is-solrcell.docx");
|
||||
POIFSFileSystem filesystem = new POIFSFileSystem(file, true);
|
||||
|
||||
// Check the encryption details
|
||||
|
@ -84,7 +95,7 @@ public class TestXWPFBugs {
|
|||
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
|
||||
Assume.assumeTrue("Please install JCE Unlimited Strength Jurisdiction Policy files for AES 256", maxKeyLen == 2147483647);
|
||||
|
||||
File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-pass.docx");
|
||||
File file = samples.getFile("bug53475-password-is-pass.docx");
|
||||
POIFSFileSystem filesystem = new POIFSFileSystem(file, true);
|
||||
|
||||
// Check the encryption details
|
||||
|
@ -117,7 +128,7 @@ public class TestXWPFBugs {
|
|||
public void bug59058() throws IOException, XmlException {
|
||||
String files[] = { "bug57031.docx", "bug59058.docx" };
|
||||
for (String f : files) {
|
||||
ZipFile zf = new ZipFile(POIDataSamples.getDocumentInstance().getFile(f));
|
||||
ZipFile zf = new ZipFile(samples.getFile(f));
|
||||
ZipArchiveEntry entry = zf.getEntry("word/document.xml");
|
||||
DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry));
|
||||
assertNotNull(document);
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue