[ 
https://issues.apache.org/jira/browse/HBASE-30304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Junegunn Choi resolved HBASE-30304.
-----------------------------------
    Fix Version/s: 2.7.0
                   2.5.16
                   2.6.7
                   3.1.0
                   3.0.1
       Resolution: Fixed

Pushed to the following branches:

* master
* branch-3
* branch-3.0
* branch-2
* branch-2.6
* branch-2.5

Thanks to [~liuxiaocs7] for the review!

> 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
>            Assignee: Junegunn Choi
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 2.7.0, 2.5.16, 2.6.7, 3.1.0, 3.0.1
>
>
> 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