Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
0.9.14
-
None
Description
The definition of guacamole instruction:
The Guacamole protocol consists of instructions. Each instruction is a comma-delimited list followed by a terminating semicolon, where the first element of the list is the instruction opcode, and all following elements are the arguments for that instruction:
OPCODE,ARG1,ARG2,ARG3,...;
Each element of the list has a positive decimal integer length prefix separated by the value of the element by a period. This length denotes the number of Unicode characters in the value of the element, which is encoded in UTF-8:
LENGTH.VALUE
Which means the element's values will be encoded in UTF-8。That means we must use correct UTF-8 encoder/decoder to handle the instruction. But in guacamole-common, the parser use Java's char type to parse which only can store partial Unicode char.
if (state == State.PARSING_CONTENT && charsParsed + elementLength + 1 <= length) { // Read element String element = new String(chunk, offset + charsParsed, elementLength); charsParsed += elementLength; elementLength = 0; ...
In the code above, bytes of a unicode char may not equal to a java char.
I also check the guacamole-server implementation, all work fine.
Correct code https://github.com/apache/guacamole-server/blob/master/src/libguac/parser.c#L113
/* Advance to next character */
parser->__element_length--;
char_buffer += char_length;