[ https://issues.apache.org/jira/browse/XERCESJ-1759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17761658#comment-17761658 ]
shuailingliang commented on XERCESJ-1759: ----------------------------------------- After adding the closing tag, the memory has not been significantly reduced. The main reason is because the depth of the element is too large. Currently, we have no way to check the depth of this element. We checked the JDK's documentation and JDK's implementation. The document address is [https://docs.oracle.com/javase/8/docs/technotes/guides/security/jaxp/jaxp.html#maxElementDepth] The commit information of JDK is: [https://github.com/openjdk/jdk/commit/98bb3f44c2498da52a96b53ed4d9ce6a0b1e620d] JDK provides a method to limit the maximum element depth, but xerces has no related method. Can this be optimized? > Parsing xml cannot limit the maximum element depth, resulting in excessive > memory usage and DOS. > ------------------------------------------------------------------------------------------------ > > Key: XERCESJ-1759 > URL: https://issues.apache.org/jira/browse/XERCESJ-1759 > Project: Xerces2-J > Issue Type: Bug > Components: JAXP (javax.xml.parsers), JAXP (javax.xml.validation) > Affects Versions: 2.12.2 > Reporter: shuailingliang > Priority: Major > Labels: security > > When parsing an xml file similar to the following by calling the > javax.xml.parsers.DocumentBuilder#parse(java.io.File) method, the elements > are nested layer by layer and there is no element closing tag. Since the > depth of elements cannot be verified, the array in > org.apache.xerces.impl.XMLDocumentFragmentScannerImpl#fElementStack will > continue to increase the number of QName objects, resulting in excessive > memory and DOS problems. > > <?xml version=”1.0” encoding=”UTF-8” standalone=”no” ?> > <A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A > a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A > a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”><A a=”1”>… > > After testing, we found that a file of 12.93M will cause an OOM exception in > a service with a maximum heap memory of 250M. > > We checked the jdk information and found that we can limit the nesting depth > of xml elements by setting the system property jdk.xml.maxElementDepth. We > hope xerces can solve this problem. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: j-dev-unsubscr...@xerces.apache.org For additional commands, e-mail: j-dev-h...@xerces.apache.org