[bug-63664] do not use DocumentBuilderFactory directly

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1865720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2019-08-22 21:57:50 +00:00
parent a3298f9c16
commit 3623bea505
2 changed files with 4 additions and 6 deletions

View File

@ -27,7 +27,6 @@ import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys; import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result; import javax.xml.transform.Result;
@ -39,6 +38,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.openxml4j.opc.internal.ZipHelper; import org.apache.poi.openxml4j.opc.internal.ZipHelper;
import org.apache.poi.openxml4j.util.ZipSecureFile; import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
@ -53,14 +53,13 @@ import org.xml.sax.InputSource;
* use different formatting of the XML. * use different formatting of the XML.
*/ */
public class OOXMLPrettyPrint { public class OOXMLPrettyPrint {
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
private final DocumentBuilder documentBuilder; private final DocumentBuilder documentBuilder;
public OOXMLPrettyPrint() throws ParserConfigurationException { public OOXMLPrettyPrint() {
// allow files with much lower inflation rate here as there is no risk of Zip Bomb attacks in this developer tool // allow files with much lower inflation rate here as there is no risk of Zip Bomb attacks in this developer tool
ZipSecureFile.setMinInflateRatio(0.00001); ZipSecureFile.setMinInflateRatio(0.00001);
documentBuilder = documentBuilderFactory.newDocumentBuilder(); documentBuilder = DocumentHelper.newDocumentBuilder();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys; import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
@ -142,7 +141,7 @@ public class WordToTextConverter extends AbstractWordConverter
public WordToTextConverter() throws ParserConfigurationException public WordToTextConverter() throws ParserConfigurationException
{ {
this.textDocumentFacade = new TextDocumentFacade( this.textDocumentFacade = new TextDocumentFacade(
DocumentBuilderFactory.newInstance().newDocumentBuilder() XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
.newDocument() ); .newDocument() );
} }