You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by "Ian Maxon (JIRA)" <ji...@apache.org> on 2015/11/09 21:38:10 UTC

[jira] [Commented] (ASTERIXDB-1166) Cannot multiply by negative 1

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

Ian Maxon commented on ASTERIXDB-1166:
--------------------------------------

I'm surprised we don't have a test to cover this.... 

The issue is in NumericMultiplyDescriptor. We try to guard overflow on the multiply using this expression: 

         long maximum = signLhs == signRhs ? Long.MAX_VALUE : Long.MIN_VALUE;

         if (lhs != 0 && (rhs > 0 && rhs > maximum / lhs || rhs < 0 && rhs < maximum / lhs))
                    throw new HyracksDataException("Overflow Happened.");

Here, maximum is Long.MIN_VALUE. rhs is 5, so it's greater than 0, but maximum / lhs (-1) *itself* creates an overflow (because -9223372036854775808 / -1 is greater than Long.MAX_VALUE by one, and hence becomes -9223372036854775808 ! ) . Therefore, the guard is broken. 

We should guard this, but properly ( see: https://www.securecoding.cert.org/confluence/display/java/NUM00-J.+Detect+or+prevent+integer+overflow ).

> Cannot multiply by negative 1
> -----------------------------
>
>                 Key: ASTERIXDB-1166
>                 URL: https://issues.apache.org/jira/browse/ASTERIXDB-1166
>             Project: Apache AsterixDB
>          Issue Type: Bug
>          Components: Hyracks
>         Environment: master (97dd45d2d4426bcb1a3971f021839dbfd7993fc2)
>            Reporter: Cameron Samak
>
> Query:
> {code}
> (-0.999 * 5)
> (-1.001 * 5)
> (-1 * 5)
> {code}
> Returns:
> {code}
> [-4.995]
> [-5.004999999999999]
> Overflow Happened. [HyracksDataException]
> {code}



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