HBase
  1. HBase
  2. HBASE-6991

Escape "\" in Bytes.toStringBinary() and its counterpart Bytes.toBytesBinary()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.95.2
    • Fix Version/s: 0.95.0
    • Component/s: util
    • Labels:
      None
    • Hadoop Flags:
      Incompatible change, Reviewed
    • Release Note:
      Hide
      This patch changes Bytes.toStringBinary() and Bytes.toBytesBinary() to escape the character "\". Unprintable characters are escaped using "\\x%02X" format, but "\" was not escaped properly leading to irreversible ser/de using toStringBinary() -> toBytesBinary().
      Show
      This patch changes Bytes.toStringBinary() and Bytes.toBytesBinary() to escape the character "\". Unprintable characters are escaped using "\\x%02X" format, but "\" was not escaped properly leading to irreversible ser/de using toStringBinary() -> toBytesBinary().

      Description

      Since "\" is used to escape non-printable character but not treated as special character in conversion, it could lead to unexpected conversion.

      For example, please consider the following code snippet.

      public void testConversion() {
        byte[] original = {
            '\\', 'x', 'A', 'D'
        };
        String stringFromBytes = Bytes.toStringBinary(original);
        byte[] converted = Bytes.toBytesBinary(stringFromBytes);
        System.out.println("Original: " + Arrays.toString(original));
        System.out.println("Converted: " + Arrays.toString(converted));
        System.out.println("Reversible?: " + (Bytes.compareTo(original, converted) == 0));
      }
      
      Output:
      -------
      Original: [92, 120, 65, 68]
      Converted: [-83]
      Reversible?: false
      

      The "\" character needs to be treated as special and must be encoded as a non-printable character ("\x5C") to avoid any kind of ambiguity during conversion.

        Issue Links

          Activity

          No work has yet been logged on this issue.

            People

            • Assignee:
              Aditya Kishore
              Reporter:
              Aditya Kishore
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development