Uploaded image for project: 'Guacamole'
  1. Guacamole
  2. GUACAMOLE-615

Incorrect instruction element length handle because of Java's char type

    XMLWordPrintableJSON

Details

    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. 

      Problem code https://github.com/apache/guacamole-client/blob/master/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleParser.java#L164  

       

      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;

       

      Attachments

        Activity

          People

            mjumper Mike Jumper
            aiden0z Aiden Luo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: