Junegunn Choi created HBASE-30304:
-------------------------------------

             Summary: Bytes.toBytesBinary throws 
StringIndexOutOfBoundsException on truncated \x escape
                 Key: HBASE-30304
                 URL: https://issues.apache.org/jira/browse/HBASE-30304
             Project: HBase
          Issue Type: Bug
            Reporter: Junegunn Choi


h2. Problem

{{Bytes.toBytesBinary}} parses {{\xNN}} hex escapes. The guard checks only that 
the {{x}} after a backslash exists ({{in.length() > i + 1}}), then reads 
{{charAt(i + 2)}} and {{charAt(i + 3)}} unconditionally, so a string ending in 
a truncated {{\x}} escape throws {{StringIndexOutOfBoundsException}}.

{code:java}
Bytes.toBytesBinary("abc\\x00\\x01\\x");  // throws, reads past end at i + 2
Bytes.toBytesBinary("abc\\x00\\x01\\x0"); // throws, reads past end at i + 3
{code}

HBASE-6518 fixed the trailing bare-backslash case ({{"...\\"}}) with the same 
guard but did not extend it to the two hex digits, so this sub-case remained.

h2. Fix

Widen the guard to {{in.length() > i + 3}} so both hex reads are in bounds. A 
truncated tail escape then falls through to the existing bogus-escape path and 
emits the backslash literally. Valid escapes and mid-string bogus escapes are 
unchanged.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to