Commit f7ff07e4 authored by guus's avatar guus

Make sure that encoding/decoding is strict (OF-391).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11844 b35dd754-fafc-0310-a699-88a17e54d16e
parent 860ab8d9
...@@ -21,6 +21,8 @@ package org.jivesoftware.openfire.nio; ...@@ -21,6 +21,8 @@ package org.jivesoftware.openfire.nio;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -101,7 +103,7 @@ class XMLLightweightParser { ...@@ -101,7 +103,7 @@ class XMLLightweightParser {
protected boolean insideChildrenTag = false; protected boolean insideChildrenTag = false;
Charset encoder; CharsetDecoder encoder;
static { static {
// Set default max buffer size to 1MB. If limit is reached then close connection // Set default max buffer size to 1MB. If limit is reached then close connection
...@@ -111,7 +113,9 @@ class XMLLightweightParser { ...@@ -111,7 +113,9 @@ class XMLLightweightParser {
} }
public XMLLightweightParser(String charset) { public XMLLightweightParser(String charset) {
encoder = Charset.forName(charset); encoder = Charset.forName(charset).newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
} }
/* /*
...@@ -204,14 +208,7 @@ class XMLLightweightParser { ...@@ -204,14 +208,7 @@ class XMLLightweightParser {
} }
buffer.append(buf, 0, readByte); 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())) {
// Empty the buffer so there is no memory leak
buffer.delete(0, buffer.length());
return;
}
}
// Robot. // Robot.
char ch; char ch;
boolean isHighSurrogate = false; boolean isHighSurrogate = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment