Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException when using com.sun.xml.bind.v2.runtime.output.C14nXmlOutput #1700

Closed
mryangza opened this issue Feb 13, 2023 · 0 comments · Fixed by #1713
Closed

Comments

@mryangza
Copy link

Hi,

The com.sun.xml.bind.v2.runtime.output.C14nXmlOutput class seems to have an out of bounds error:

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 8 out of bounds for length 8
	at com.sun.xml.bind.v2.runtime.output.C14nXmlOutput.attribute(C14nXmlOutput.java:126)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:416)
	at com.sun.xml.bind.v2.runtime.property.AttributeProperty.serializeAttributes(AttributeProperty.java:73)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassBeanInfoImpl.java:352)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:659)
	at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:128)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:329)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:666)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:39)
	at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:142)
	at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:129)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:329)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:563)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:310)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:464)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:298)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:226)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)

This class is used whenever the com.sun.xml.bind.c14n property is set to true and the jaxb.formatted.output property is set to false.

The offending code seems to be the highlighted bit here in com.sun.xml.bind.v2.runtime.output.C14nXmlOutput#attribute(com.sun.xml.bind.v2.runtime.Name, java.lang.String):

    @Override
    public void attribute(Name name, String value) throws IOException {
        if(staticAttributes.length==len) {
            // reallocate
            int newLen = len*2;
            StaticAttribute[] newbuf = new StaticAttribute[newLen];
            System.arraycopy(staticAttributes,0,newbuf,0,len);
            for(int i=len;i<newLen;i++)
                staticAttributes[i] = new StaticAttribute(); <--- This should read newBuf[i] = new StaticAttribute();
            staticAttributes = newbuf;
        }

        staticAttributes[len++].set(name,value);
    }

Thoughts? Is there a workaround for getting C14N formatted output without also setting jaxb.formatted.output to true to avoid this problem?

lukasj added a commit to lukasj/jaxb-ri that referenced this issue May 20, 2023
…xml.bind.v2.runtime.output.C14nXmlOutput

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit that referenced this issue May 20, 2023
…runtime.output.C14nXmlOutput

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit to lukasj/jaxb-ri that referenced this issue Oct 9, 2023
….xml.bind.v2.runtime.output.C14nXmlOutput

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 2bbf269)
lukasj added a commit that referenced this issue Oct 13, 2023
….runtime.output.C14nXmlOutput

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 2bbf269)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant