Commit a77ba027 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Recognize invalid surrogate characters. JM-1388

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/openfire_3_5_2@10508 b35dd754-fafc-0310-a699-88a17e54d16e
parent cb594811
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2008 Jive Software. All rights reserved. * Copyright (C) 2005-2008 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license * a copy of which is included in this distribution, or a commercial license
...@@ -168,6 +168,11 @@ class XMLLightweightParser { ...@@ -168,6 +168,11 @@ class XMLLightweightParser {
char[] buf = charBuffer.array(); char[] buf = charBuffer.array();
int readByte = charBuffer.remaining(); int readByte = charBuffer.remaining();
// Just return if nothing was read
if (readByte == 0) {
return;
}
// Verify if the last received byte is an incomplete double byte character // Verify if the last received byte is an incomplete double byte character
char lastChar = buf[readByte-1]; char lastChar = buf[readByte-1];
if (lastChar >= 0xfff0) { if (lastChar >= 0xfff0) {
...@@ -197,8 +202,26 @@ class XMLLightweightParser { ...@@ -197,8 +202,26 @@ class XMLLightweightParser {
} }
// Robot. // Robot.
char ch; char ch;
boolean isHighSurrogate = false;
for (int i = 0; i < readByte; i++) { for (int i = 0; i < readByte; i++) {
ch = buf[i]; ch = buf[i];
if (isHighSurrogate) {
if (Character.isLowSurrogate(ch)) {
// Everything is fine. Clean up traces for surrogates
isHighSurrogate = false;
}
else {
// Trigger error. Found high surrogate not followed by low surrogate
throw new Exception("Found high surrogate not followed by low surrogate");
}
}
else if (Character.isHighSurrogate(ch)) {
isHighSurrogate = true;
}
else if (Character.isLowSurrogate(ch)) {
// Trigger error. Found low surrogate char without a preceding high surrogate
throw new Exception("Found low surrogate char without a preceding high surrogate");
}
if (status == XMLLightweightParser.TAIL) { if (status == XMLLightweightParser.TAIL) {
// Looking for the close tag // Looking for the close tag
if (depth < 1 && ch == head.charAt(tailCount)) { if (depth < 1 && ch == head.charAt(tailCount)) {
......
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