[ 
https://issues.apache.org/jira/browse/DERBY-2935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12512894
 ] 

Knut Anders Hatlen commented on DERBY-2935:
-------------------------------------------

Adding a test which used 8 bytes for the length wasn't that difficult, but 
since there is no way of sending data that needs the high four bytes of the 
length field, the test passes regardless of the fix. So I guess the best way to 
demonstrate the bug and the fix is by running this program:

public class ll {
    public static void main(String[] args) {
        long l1 = ((byte) 1 & 0xFF) << 56;
        long l2 = ((byte) 1 & 0xFFL) << 56;
        System.out.println("l1 = " + l1);
        System.out.println("l2 = " + l2);
    }
}

Which prints:

l1 = 16777216
l2 = 72057594037927936

> DDMReader.readLengthAndCodePoint() decodes long integer incorrectly
> -------------------------------------------------------------------
>
>                 Key: DERBY-2935
>                 URL: https://issues.apache.org/jira/browse/DERBY-2935
>             Project: Derby
>          Issue Type: Bug
>          Components: Network Server
>    Affects Versions: 10.1.3.1, 10.2.2.0, 10.3.1.1, 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: decode-long.diff
>
>
> DDMReader.readLengthAndCodePoint() contains code to decode a long integer 
> from a byte array. This code is broken since it uses int operations and not 
> long operations in the decoding. The long might be encoded using four, six or 
> eight bytes, and since Derby currently always uses the four bytes encoding, 
> the bug is not exposed in the current code.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to