You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@guacamole.apache.org by "Mike Jumper (Jira)" <ji...@apache.org> on 2023/05/09 21:46:00 UTC
[jira] [Closed] (GUACAMOLE-615) Incorrect instruction element length handle because of Java's char type
[ https://issues.apache.org/jira/browse/GUACAMOLE-615?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mike Jumper closed GUACAMOLE-615.
---------------------------------
Resolution: Fixed
> Incorrect instruction element length handle because of Java's char type
> -----------------------------------------------------------------------
>
> Key: GUACAMOLE-615
> URL: https://issues.apache.org/jira/browse/GUACAMOLE-615
> Project: Guacamole
> Issue Type: Bug
> Components: guacamole-common, guacamole-common-js
> Affects Versions: 0.9.14
> Reporter: Aiden Luo
> Assignee: Mike Jumper
> Priority: Minor
> Fix For: 1.5.2
>
>
> The definition of guacamole instruction:
> {quote}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
> {quote}
> 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.
> Problem code [https://github.com/apache/guacamole-client/blob/master/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleParser.java#L164]
>
> {code:java}
> if (state == State.PARSING_CONTENT && charsParsed + elementLength + 1 <= length) {
> // Read element
> String element = new String(chunk, offset + charsParsed, elementLength);
> charsParsed += elementLength;
> elementLength = 0;
> ...{code}
> 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]
> {code:java}
> /* Advance to next character */
> parser->__element_length--;
> char_buffer += char_length;{code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)