[jira] [Commented] (COMPRESS-411) TarUtils.formatLongOctalOrBinaryBytes never uses result of formatLongBinary

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (COMPRESS-411) TarUtils.formatLongOctalOrBinaryBytes never uses result of formatLongBinary

JIRA jira@apache.org

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

Stefan Bodewig commented on COMPRESS-411:
-----------------------------------------

We deliberately store negative numbers in binary fields, yes.

You are certainly correct the code looks weird, {{formatBigIntegerBinary}} should probably be executed inside an {{else}} branch.

It's been a long time since I've last looked at the way binary numbers are stored, but looking at the code we don't use the most significant bit to signal negative numbers but the first byte - which is 0xff for negative numbers and only the remaining 7 bytes are used. But we can use all 56 bits of these 7 bytes (assuming length is 8).

As we are calculating the twos-complement in {{formatLongBinary}} I think we should be safe, if we did it correctly :-) Fix will be available soon.

Also

{code}
        long val = Math.abs(value);
{code}

is going to result in a negative value for {{Long.MIN_VALUE}}.

> TarUtils.formatLongOctalOrBinaryBytes never uses result of formatLongBinary
> ---------------------------------------------------------------------------
>
>                 Key: COMPRESS-411
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-411
>             Project: Commons Compress
>          Issue Type: Bug
>          Components: Archivers
>    Affects Versions: 1.14
>            Reporter: Simon Spero
>            Priority: Minor
>
> if the length < 9, formatLongBinary is executed, then overwritten by the results of formatBigIntegerBinary.
> If the results are not ignored, a unit test would fail.
> Also, do the binary hacks  need to support negative numbers?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)