Openfire 3.7.1 - Emojis in MUC kill chat connection

Hi!

When you send an Emoji character to a MUC chat room (don’t know if this applies to “normal” chats, too) from your iPhone to a Openfire 3.7.1 server the connection is closed by the server.

Similar report under http://community.igniterealtime.org/message/218253#218253 and in consequence as issue http://issues.igniterealtime.org/browse/OF-455 but due to the age of the thread, the different version and the different stacktrace I thought it might be not directly related.

Stacktrace for the error:

2012.10.30 15:49:36 org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to error while processing message: ������

java.lang.NumberFormatException: For input string: “?”

at java.lang.NumberFormatException.forInputString(Unknown Source)

at java.lang.Integer.parseInt(Unknown Source)

at org.jivesoftware.openfire.net.MXParser.more(MXParser.java:384)

at org.jivesoftware.openfire.net.MXParser.nextImpl(MXParser.java:85)

at org.xmlpull.mxp1.MXParser.nextToken(MXParser.java:1100)

at org.dom4j.io.XMPPPacketReader.parseDocument(XMPPPacketReader.java:317)

at org.dom4j.io.XMPPPacketReader.read(XMPPPacketReader.java:154)

at org.jivesoftware.openfire.net.StanzaHandler.process(StanzaHandler.java:159)

at org.jivesoftware.openfire.nio.ConnectionHandler.messageReceived(ConnectionHandl er.java:169)

at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived (AbstractIoFilterChain.java:570)

at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Ab stractIoFilterChain.java:299)

at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilt erChain.java:53)

at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceive d(AbstractIoFilterChain.java:648)

at org.apache.mina.common.IoFilterAdapter.messageReceived(IoFilterAdapter.java:80)

at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Ab stractIoFilterChain.java:299)

at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilt erChain.java:53)

at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceive d(AbstractIoFilterChain.java:648)

at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimplePr otocolDecoderOutput.java:58)

at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecF ilter.java:185)

at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Ab stractIoFilterChain.java:299)

at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilt erChain.java:53)

at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceive d(AbstractIoFilterChain.java:648)

at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java :239)

at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(Execut orFilter.java:283)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)

at java.lang.Thread.run(Unknown Source)

Best regards,

René

Sending emoji cut & pasted from

https://en.wikipedia.org/wiki/Emoji#Regional_Indicator_Symbols (second block labelled “Emoticons”) will

disconnect the user. Tried with two different clients (Linux, not iPhone) so it seems to be a server problem.

The message does not reach the recipient.

1 Like

I have added this to the ticket comment.

1 Like

Same issue here. Any word on a fix?

change org.jivesoftware.openfire.net.StanzaHandler

line 159:Element doc = reader.read(new StringReader(stanza)).getRootElement();

to:Element doc = reader.parseDocument(stanza).getRootElement();

will fix this issue.

my question is i can’t insert emoji into database.

i use mysql and CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci,

when i insert emoji into database from JBOSS,it works fine,

but when i do the same thing from Openfire,i got this:

java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x98\x84\xF0\x9F…’ for column ‘name’ at row 1

help me out,thank you!

This answer is ambiguous, are you saying that doing the following:

in the file org.jivesoftware.openfire.net.StanzaHandler at line 159:

change this:

Element doc = reader.read(new StringReader(stanza)).getRootElement();

to this:

Element doc = reader.parseDocument(stanza).getRootElement();

will fix the Emoji issue?

yeh! You say I want to say.

Forgive my poor english!

Where exactly is that file to be found on a Windows system? Version 3.8.2 in the mean time. Thanks

He meant in the source code, not in the working binaries that you have installed. After changing the code Openfire have to be compiled again.

Thanks

The better work around for this issue should modifying MXParser.java file, especially the Line 378/379:

((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||

((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||

Merge the two conditions into one condition:

((codePoint >= 0x20) && (codePoint <= 0xFFFD)) ||

Not really an ideal fix, as it will allow many illegal characters to be exchanged, which may opens a DOS attack vector.

I’ve commited r13995 and r13996, which fixes the emoji problem for openfire and keeps the strictnes wrt illegal unicode characters in XMPP/XML.

Flow, thanks for your fix. Does it solve OF-455 ? If so, can you resolve the Jira issue?

Emojis work fine now, and the silly NumberFormatException bug is also fixed.

Not sure if OF-455 is the same cause, as it comes from Apache MINA. AFAIKT this it not what caused openfire to terminate the connection when emojis are send, which is fixed now.

It works fine, but if you restart the server go to the MUC the emoji doesn’t appear.

I am using mySQL. So maybe it has something to do with the way mySQL handles utf-8.