powered by Jive Software

Bug in XMLLightWeightParser

If message contains multibyte characters parsing can adds null characters to the random place of resulting stanza. For example next simple test will fail:

package org.jivesoftware.openfire.nio;

import org.junit.Assert;

import org.apache.mina.common.ByteBuffer;

import org.junit.Test;

public class XMLLightweightParserTest {

@Test

public void testRead() {

try {

XMLLightweightParser parser = new XMLLightweightParser(“UTF-8”);

String xml1 = " 1) {

Assert.fail(“More than one message found”);

}

else {

Assert.assertEquals(xml1 + xml2, msgs[0]);

}

} catch (Exception e) {

Assert.fail(e.getMessage());

}

}

}

/code

This patch fix the problem:

Index: XMLLightweightParser.java

===================================================================

— XMLLightweightParser.java (revision 8950)

+++ XMLLightweightParser.java (working copy)

@@ -144,8 +144,6 @@

  • Main reading method

*/

public void read(ByteBuffer byteBuffer) throws Exception {

  •    int readByte = byteBuffer.remaining();
    

invalidateBuffer();

// Check that the buffer is not bigger than 1 Megabyte. For security reasons

// we will abort parsing when 1 Mega of queued chars was found.

@@ -154,8 +152,9 @@

}

CharBuffer charBuffer = encoder.decode(byteBuffer.buf());

char[] buf = charBuffer.array();

  •    int readByte = charBuffer.remaining();
    
  •    buffer.append(buf);
    
  •    buffer.append(buf, 0, readByte);
    

// Do nothing if the buffer only contains white spaces

if (buffer.charAt(0) <= ’ ’ && buffer.charAt(buffer.length()-1) <= ’ ') {

if ("".equals(buffer.toString().trim())) {

/code

hy,

can these result in a never ending stanza exception?

i sometimes get this error (with a connection manager running) - what results in drops of 1 MB of correct stanzas. i already started to put in some debugging code and decreased the size. but i have always have to restart the server (what i only can to on late night ant not every day) and the error occurs pherhaps twice a week.

notz

Yes, it can. If you are using not english characters.

thanks, it resolved my never ending stanza problem. applied the patch on 21th of august and never got this error again.

I have the exact same problem with openfire 3.3.3 and psi 0.10. I’d be nice if anyone could fix it.

Hey Piti,

Tim’s patch has been applied to Openfire 3.3.3 as shown in JM-1127. Are you sure you are seeing the same problem? Could you give us more information about the problem you are seeing and how we can reproduce it?

Thanks,

– Gato

Thanks for your reply

I think I posted it in a wrong topic. The problem I am facing is more like this one http://www.igniterealtime.org/community/message/157456#157456. It seems to me that the thing fnx suspect is right.

The problem is not entirely reproducible. It occurs randomly but often enough to be annoyed with. To be more quantitative, it think it happen more than once in every 1000 characters. To reproduce this problem, you can just keep sending utf-8 string (for me Thai) to your friend. Once in a while it will be turned in to �� or ��� (depending on where the buffer chop off the bytestream, i guess).

I was suspecting that it’s sun’s java’s bug. So, I change the java version from 6 to 1.5. But the problem is still there.

My System is Ubuntu 7.10 , sun’s java6 , openfire3.3.0.

Thanks