Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_unixtime() crashes with error: nan is outside the range of representable values of type 'long' #2791

Closed
kagamiori opened this issue Oct 8, 2022 · 1 comment
Assignees
Labels
bug Something isn't working fuzzer-found

Comments

@kagamiori
Copy link
Contributor

kagamiori commented Oct 8, 2022

This should be easy to reproduce by sending a input vector that contains nan to from_unitxtime as the first argument.

======> Started iteration 0 (seed: 1731413369)
I1008 09:29:24.089392 1177466 ExpressionFuzzer.cpp:798] Executing expression: from_unixtime(asin(asin(ceil(atan2("c0","c1")))),"c2")
I1008 09:29:24.089566 1177466 ExpressionFuzzer.cpp:801] 3 vectors as input:
I1008 09:29:24.089591 1177466 ExpressionFuzzer.cpp:803] 	[DICTIONARY DOUBLE: 100 elements, 7 nulls], [FLAT DOUBLE: 100 elements, 3 nulls]
I1008 09:29:24.089706 1177466 ExpressionFuzzer.cpp:803] 	[DICTIONARY DOUBLE: 100 elements, 16 nulls], [DICTIONARY DOUBLE: 100 elements, 10 nulls], [FLAT DOUBLE: 100 elements, 17 nulls]
I1008 09:29:24.089792 1177466 ExpressionFuzzer.cpp:803] 	[FLAT VARCHAR: 100 elements, 8 nulls]
velox/functions/prestosql/FromUnixTime.cpp:24:10: runtime error: nan is outside the range of representable values of type 'long'
    #0 0x7ff71d1f1602 in facebook::velox::functions::(anonymous namespace)::toMillis(double) velox/functions/prestosql/FromUnixTime.cpp:24
    #1 0x7ff71d1f2bb8 in auto facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)::operator()<int>(auto) const velox/functions/prestosql/FromUnixTime.cpp:64
    #2 0x7ff71d1f402b in void facebook::velox::bits::forEachBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, bool, auto)::'lambda'(int, unsigned long)::operator()(int, unsigned long) const velox/common/base/BitUtil.h:348
    #3 0x7ff71d1f3adf in void facebook::velox::bits::forEachWord<void facebook::velox::bits::forEachBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, bool, auto)::'lambda'(int, unsigned long), void facebook::velox::bits::forEachBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, bool, auto)::'lambda'(int)>(int, int, auto, void facebook::velox::bits::forEachBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, bool, auto)::'lambda'(int)) velox/common/base/BitUtil.h:186
    #4 0x7ff71d1f36fb in void facebook::velox::bits::forEachBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, bool, auto) velox/common/base/BitUtil.h:339
    #5 0x7ff71d1f31da in void facebook::velox::bits::forEachSetBit<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(unsigned long const*, int, int, auto) velox/common/base/BitUtil.h:373
    #6 0x7ff71d1ef0c2 in void facebook::velox::SelectivityVector::applyToSelected<facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const::'lambda0'(auto)>(auto) const velox/vector/SelectivityVector.h:432
    #7 0x7ff71d1ede4c in facebook::velox::functions::(anonymous namespace)::FromUnixtimeFunction::apply(facebook::velox::SelectivityVector const&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&, std::shared_ptr<facebook::velox::Type const> const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) const velox/functions/prestosql/FromUnixTime.cpp:63
    #8 0x7ff718f19bf1 in facebook::velox::exec::Expr::applyFunction(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) velox/expression/Expr.cpp:1386
    #9 0x7ff718f1c80b in facebook::velox::exec::Expr::evalAll(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) velox/expression/Expr.cpp:1210
    #10 0x7ff718f239dc in facebook::velox::exec::Expr::evalWithNulls(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) velox/expression/Expr.cpp:939
    #11 0x7ff718f1de21 in facebook::velox::exec::Expr::evalEncodings(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&) velox/expression/Expr.cpp:847
    #12 0x7ff718f1ae4a in facebook::velox::exec::Expr::eval(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::shared_ptr<facebook::velox::BaseVector>&, bool) velox/expression/Expr.cpp:521
    #13 0x7ff718f2ac8f in facebook::velox::exec::ExprSet::eval(int, int, bool, facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&) velox/expression/Expr.cpp:1584
    #14 0x7ff71c39f285 in facebook::velox::exec::ExprSet::eval(facebook::velox::SelectivityVector const&, facebook::velox::exec::EvalCtx&, std::vector<std::shared_ptr<facebook::velox::BaseVector>, std::allocator<std::shared_ptr<facebook::velox::BaseVector> > >&) velox/expression/Expr.h:520
    #15 0x7ff71c39bbc1 in facebook::velox::test::(anonymous namespace)::ExpressionFuzzer::executeExpression(std::shared_ptr<facebook::velox::core::ITypedExpr const> const&, std::shared_ptr<facebook::velox::RowVector> const&, bool) velox/expression/tests/ExpressionFuzzer.cpp:834
    #16 0x7ff71c2be547 in facebook::velox::test::(anonymous namespace)::ExpressionFuzzer::go() velox/expression/tests/ExpressionFuzzer.cpp:921
    #17 0x7ff71c2b86cd in facebook::velox::test::expressionFuzzer(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<facebook::velox::exec::FunctionSignature const*, std::allocator<facebook::velox::exec::FunctionSignature const*> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<facebook::velox::exec::FunctionSignature const*, std::allocator<facebook::velox::exec::FunctionSignature const*> > > > >, unsigned long) velox/expression/tests/ExpressionFuzzer.cpp:999
    #18 0x2c4b93 in FuzzerRunner::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, std::unordered_set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) velox/expression/tests/FuzzerRunner.h:108
    #19 0x2c3fba in main velox/expression/tests/ExpressionFuzzerTest.cpp:89
    #20 0x7ff719975656 in __libc_start_call_main /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #21 0x7ff719975717 in __libc_start_main_impl /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../csu/libc-start.c:409:3
    #22 0x2b94a0 in _start /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/x86_64/start.S:116

SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow velox/functions/prestosql/FromUnixTime.cpp:24:10 in 
@kagamiori kagamiori added bug Something isn't working fuzzer-found labels Oct 8, 2022
@mbasmanova mbasmanova self-assigned this Oct 24, 2022
@mbasmanova
Copy link
Contributor

In Presto, nan input is treated as zero.

presto> select from_unixtime(nan(), '+04:00');
             _col0
--------------------------------
 1970-01-01 04:00:00.000 +04:00
(1 row)

    @ScalarFunction("from_unixtime")
    @SqlType(StandardTypes.TIMESTAMP)
    public static long fromUnixTime(@SqlType(StandardTypes.DOUBLE) double unixTime)
    {
        return Math.round(unixTime * 1000);
    }

    /**
     * Returns the closest {@code long} to the argument, with ties
     * rounding to positive infinity.
     *
     * <p>Special cases:
     * <ul><li>If the argument is NaN, the result is 0.
     * ...
     */
    public static long round(double a) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer-found
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants