From 3623bea5058cb642888a7199e5ceaecdac4c0a62 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 22 Aug 2019 21:57:50 +0000 Subject: [PATCH] [bug-63664] do not use DocumentBuilderFactory directly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1865720 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java | 7 +++---- .../org/apache/poi/hwpf/converter/WordToTextConverter.java | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java b/src/ooxml/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java index e48f65ffb9..6cf5eb2cfb 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java +++ b/src/ooxml/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java @@ -27,7 +27,6 @@ import java.util.zip.ZipException; import java.util.zip.ZipOutputStream; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; @@ -39,6 +38,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; 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.util.ZipSecureFile; import org.apache.poi.util.IOUtils; @@ -53,14 +53,13 @@ import org.xml.sax.InputSource; * use different formatting of the XML. */ public class OOXMLPrettyPrint { - private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 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 ZipSecureFile.setMinInflateRatio(0.00001); - documentBuilder = documentBuilderFactory.newDocumentBuilder(); + documentBuilder = DocumentHelper.newDocumentBuilder(); } public static void main(String[] args) throws Exception { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java index b469df3031..399029233d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; @@ -142,7 +141,7 @@ public class WordToTextConverter extends AbstractWordConverter public WordToTextConverter() throws ParserConfigurationException { this.textDocumentFacade = new TextDocumentFacade( - DocumentBuilderFactory.newInstance().newDocumentBuilder() + XMLHelper.getDocumentBuilderFactory().newDocumentBuilder() .newDocument() ); }