Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-6991

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.95.2
    • 0.95.0
    • util
    • None
    • Incompatible change, Reviewed
    • 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.

      Attachments

        1. HBASE-6991_trunk.patch
          5 kB
          Aditya Kishore

        Issue Links

          Activity

            People

              adityakishore Aditya Kishore
              adityakishore Aditya Kishore
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: