Bug 41573 - XMLCipher StackOverflowError
Summary: XMLCipher StackOverflowError
Status: RESOLVED DUPLICATE of bug 42886
Alias: None
Product: Security - Now in JIRA
Classification: Unclassified
Component: Encryption (show other bugs)
Version: unspecified
Hardware: PC other
: P2 normal
Target Milestone: ---
Assignee: XML Security Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-08 11:48 UTC by Marek Jablonski
Modified: 2008-02-19 07:01 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Jablonski 2007-02-08 11:48:38 UTC
When encrypt xml documents large then 5MB 
using org.apache.xml.security.encryption.XMLCipher 

Exception in thread "main" java.lang.StackOverflowError
>         at org.apache.xerces.dom.ParentNode.internalRemoveChild(Unknown Source)
>         at org.apache.xerces.dom.ParentNode.removeChild(Unknown Source)
>         at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
> urce)
>         at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So

then bag is in implementation : (recursive invocation)

    private void removeContent(Node node) {
        NodeList list = node.getChildNodes();
        if (list.getLength() > 0) {
            Node n = list.item(0);
            if (null != n) {
                n.getParentNode().removeChild(n);
            }
            removeContent(node);
        }
    }


I'm sugesting change it, for example:

    private void removeContent(Node node) {
        NodeList list = node.getChildNodes();
        while(list.getLength() > 0) {
            Node n = list.item(0);
            if (null != n) {
                n.getParentNode().removeChild(n);
            }
        }
    }
Comment 1 sean.mullan 2007-02-12 11:27:14 UTC
Fixed.
Comment 2 sean.mullan 2007-09-19 12:29:44 UTC
Closing old bugs. Fixed in 1.4.1
Comment 3 Gill Bates 2008-02-16 14:41:46 UTC
removeContent doesn't work reliably in 1.4.1
it does not remove all children.

the loop finishes to early

I've found this buggy code
private void removeContent(Node node) {
        NodeList list = node.getChildNodes();
        for (int i=0; i<list.getLength(); i++) {
            Node n = list.item(i);
            if (n != null) {
                n.getParentNode().removeChild(n);
            }
        }
    }
example: if you have two childs, the first is removed, getLength is changed, the
second child isn't removed

Try the suggestion from the first poster
Comment 4 sean.mullan 2008-02-19 07:01:33 UTC
(In reply to comment #3)
> removeContent doesn't work reliably in 1.4.1
> it does not remove all children.

This is a dup of bug #42886, which will be fixed in 1.4.2.

*** This bug has been marked as a duplicate of 42886 ***