[ 
https://issues.apache.org/jira/browse/TRAFODION-1853?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15285933#comment-15285933
 ] 

ASF GitHub Bot commented on TRAFODION-1853:
-------------------------------------------

GitHub user ryzuo opened a pull request:

    https://github.com/apache/incubator-trafodion/pull/486

    [TRAFODION-1853] Fix overflow of long type bit wise shifting in T4 
LogicalByteArray

    Both extractLong() methods of LogicalByteArray and Bytes classes are using 
bit wise shifting to extract the long value from byte array, but larger then 32 
bit wise shifting will overflow. Change to use java.nio.ByteBuffer to construct 
and convert the long value from the source byte array.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ryzuo/incubator-trafodion jira1853

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-trafodion/pull/486.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #486
    
----
commit 04e22e5ecfc018d1d19d385efb88e89114c12039
Author: ryzuo <joshuamur...@gmail.com>
Date:   2016-05-17T02:56:29Z

    Fix JIRA1853
    
    Use ByteBuffer to construct and convert the long value from
    the source byte array.

----


> Bitwise shifting overflows when extracting long value from byte buffer in 
> JDBC T4 driver.
> -----------------------------------------------------------------------------------------
>
>                 Key: TRAFODION-1853
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-1853
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: client-jdbc-t4
>            Reporter: RuoYu Zuo
>            Assignee: RuoYu Zuo
>            Priority: Critical
>
> There's overflow been found in method extractLong() of class 
> LogicalByteArray, see code below:
>      long extractLong() {
>          long value;
>          if (swap) {
>              value = ((array[loc]) & 0x00000000000000ffL) | ((array[loc + 1] 
> << 8) & 0x000000000000ff00L)
>                      | ((array[loc + 2] << 16) & 0x0000000000ff0000L) | 
> ((array[loc + 3] << 24) & 0x00000000ff000000L)
>                      | ((array[loc + 4] << 32) & 0x000000ff00000000L) | 
> ((array[loc + 5] << 40) & 0x0000ff0000000000L)
>                      | ((array[loc + 6] << 48) & 0x00ff000000000000L) | 
> ((array[loc + 7] << 56) & 0xff00000000000000L);
>          } else {
>              value = ((array[loc + 7]) & 0x00000000000000ffL) | ((array[loc + 
> 6] << 8) & 0x000000000000ff00L)
>                      | ((array[loc + 5] << 16) & 0x0000000000ff0000L) | 
> ((array[loc + 4] << 24) & 0x00000000ff000000L)
>                      | ((array[loc + 3] << 32) & 0x000000ff00000000L) | 
> ((array[loc + 2] << 40) & 0x0000ff0000000000L)
>                      | ((array[loc + 1] << 48) & 0x00ff000000000000L) | 
> ((array[loc] << 56) & 0xff00000000000000L);
>          }
>          loc += 8;
>          return value;
>      }
> By default, the bitwise shifting is based on 4 byte int, thus << 32 and >> 32 
> is the maximum bits of shifting allowed, larger than this causes overflows. 
> In this case, the long value extracted by this method will never be correct 
> from 5th byte to 8th byte.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to