[ 
https://issues.apache.org/jira/browse/GUACAMOLE-616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16591385#comment-16591385
 ] 

Aiden Luo commented on GUACAMOLE-616:
-------------------------------------

Sorry for duplicate post.

> Incorrect instruction element length handle because of Java's char type
> -----------------------------------------------------------------------
>
>                 Key: GUACAMOLE-616
>                 URL: https://issues.apache.org/jira/browse/GUACAMOLE-616
>             Project: Guacamole
>          Issue Type: Bug
>          Components: guacamole-common
>    Affects Versions: 0.9.14
>            Reporter: Aiden Luo
>            Priority: Major
>
> 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
(v7.6.3#76005)

Reply via email to