Skip to content

Forbid lcm/gcd for floats (and few UBsan reports fixes) - #19532

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
azat:UBsan-report-fixes-v2
Jan 26, 2021
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
azat:UBsan-report-fixes-v2

Conversation

@azat

@azat azat commented Jan 24, 2021 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Forbid lcm/gcd for floats

Detailed description / Documentation draft:
Also this PR contains some UBs fixes in:

  • lcm
  • addYears
  • gcd

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jan 24, 2021
Comment thread src/Functions/lcm.cpp Resolved
@alexey-milovidov alexey-milovidov self-assigned this Jan 24, 2021
@qoega

qoega commented Jan 25, 2021

Copy link
Copy Markdown
Member

Fuzzer fail is related

SELECT lcm(NULL, NULL), lcm(nan, 2), lcm(NULL, 65537)

../src/Functions/lcm.cpp:56:77: runtime error: nan is outside the range of representable values of type 'long'
2021.01.25 03:18:20.586502 [ 155 ] {} <Fatal> BaseDaemon: ########################################
2021.01.25 03:18:20.586604 [ 155 ] {} <Fatal> BaseDaemon: (version 21.2.1.5792, build id: 01191C647E161852A9D975E63CF72E61FE4ACECC) (from thread 89) (query_id: a9ca8c0b-058e-43bc-ac01-b7ed68feecaa) Received signal Unknown signal (-3)
2021.01.25 03:18:20.586642 [ 155 ] {} <Fatal> BaseDaemon: Sanitizer trap.
2021.01.25 03:18:20.586715 [ 155 ] {} <Fatal> BaseDaemon: Stack trace: 0xe3cb7d5 0xe5f6216 0xe38f796 0xe39d22f 0x12e7109c 0x12e69664 0x12dd027f 0x12dcfe61 0x12dcf686 0x12dceffc 0x11f3f255 0x11f44637 0x129f4ddb 0x129f5dde 0x19f01c11 0x19f01436 0x1a6949af 0x1a6a5f83 0x1a69ca29 0x1a6a2370 0x1a6781e2 0x1a666060 0x1a66e34b 0x1a672667 0x1a3d979e 0x1a3d0e5c 0x1a3cc0f3 0x1a3c9f0a 0x1a6c9ed8 0x1a6c7374 0x1a6c56ed 0x1a357556
2021.01.25 03:18:20.586871 [ 155 ] {} <Fatal> BaseDaemon: 0. ./obj-x86_64-linux-gnu/../src/Common/StackTrace.cpp:293: StackTrace::StackTrace() @ 0xe3cb7d5 in /workspace/clickhouse
2021.01.25 03:18:20.587209 [ 155 ] {} <Fatal> BaseDaemon: 1. ./obj-x86_64-linux-gnu/../base/daemon/BaseDaemon.cpp:380: sanitizerDeathCallback() @ 0xe5f6216 in /workspace/clickhouse
2021.01.25 03:18:20.590866 [ 155 ] {} <Fatal> BaseDaemon: 2. __sanitizer::Die() @ 0xe38f796 in /workspace/clickhouse
2021.01.25 03:18:20.594549 [ 155 ] {} <Fatal> BaseDaemon: 3. ? @ 0xe39d22f in /workspace/clickhouse
2021.01.25 03:18:20.598195 [ 155 ] {} <Fatal> BaseDaemon: 4. std::__1::enable_if<((!(is_big_int_v<double>)) && (!(is_big_int_v<char8_t>))) && (!(is_big_int_v<char8_t>)), char8_t>::type DB::(anonymous namespace)::LCMImpl<double, char8_t>::apply<double>(double, char8_t) @ 0x12e7109c in /workspace/clickhouse
2021.01.25 03:18:20.601905 [ 155 ] {} <Fatal> BaseDaemon: 5. _ZN2DBL16castTypeToEitherIJNS_14DataTypeNumberIDuEENS1_ItEENS1_IjEENS1_ImEENS1_IN4wide7integerILm256EjEEEENS1_IaEENS1_IsEENS1_IiEENS1_IlEENS1_InEENS1_INS7_ILm256EiEEEENS1_IfEENS1_IdEENS_12DataTypeDateENS_16DataTypeDateTimeENS_15DataTypeDecimalINS_7DecimalIiEEEENSL_INSM_IlEEEENSL_INSM_InEEEENSL_INSM_ISF_EEEENS_19DataTypeFixedStringEENS_9IDataTypeEZZNS_24FunctionBinaryArithmeticINS_12_GLOBAL__N_17LCMImplENSY_7NameLCMELb0EE13castBothTypesIZNKS11_11executeImplERKNSt3__16vectorINS_21ColumnWithTypeAndNameENS13_9allocatorIS15_EEEERKNS13_10shared_ptrIKSW_EEmEUlRKT_RKT0_E_EEbPS1C_S1N_OS1G_ENKUlS1I_E_clISI_EEDaS1I_EUlS1I_E_EEbPS1K_OT1_ @ 0x12e69664 in /workspace/clickhouse
2021.01.25 03:18:20.605647 [ 155 ] {} <Fatal> BaseDaemon: 6. auto bool DB::FunctionBinaryArithmetic<DB::(anonymous namespace)::LCMImpl, DB::(anonymous namespace)::NameLCM, false>::castBothTypes<DB::FunctionBinaryArithmetic<DB::(anonymous namespace)::LCMImpl, DB::(anonymous namespace)::NameLCM, false>::executeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const::'lambda'(auto const&, auto const&)>(DB::IDataType const*, DB::IDataType const*, auto&&)::'lambda'(auto const&)::operator()<DB::DataTypeNumber<double> >(auto const&) const @ 0x12dd027f in /workspace/clickhouse
2021.01.25 03:18:20.609226 [ 155 ] {} <Fatal> BaseDaemon: 7. _ZN2DBL16castTypeToEitherIJNS_14DataTypeNumberIDuEENS1_ItEENS1_IjEENS1_ImEENS1_IN4wide7integerILm256EjEEEENS1_IaEENS1_IsEENS1_IiEENS1_IlEENS1_InEENS1_INS7_ILm256EiEEEENS1_IfEENS1_IdEENS_12DataTypeDateENS_16DataTypeDateTimeENS_15DataTypeDecimalINS_7DecimalIiEEEENSL_INSM_IlEEEENSL_INSM_InEEEENSL_INSM_ISF_EEEENS_19DataTypeFixedStringEENS_9IDataTypeEZNS_24FunctionBinaryArithmeticINS_12_GLOBAL__N_17LCMImplENSY_7NameLCMELb0EE13castBothTypesIZNKS11_11executeImplERKNSt3__16vectorINS_21ColumnWithTypeAndNameENS13_9allocatorIS15_EEEERKNS13_10shared_ptrIKSW_EEmEUlRKT_RKT0_E_EEbPS1C_S1N_OS1G_EUlS1I_E_EEbPS1K_OT1_ @ 0x12dcfe61 in /workspace/clickhouse
2021.01.25 03:18:20.612846 [ 155 ] {} <Fatal> BaseDaemon: 8. DB::FunctionBinaryArithmetic<DB::(anonymous namespace)::LCMImpl, DB::(anonymous namespace)::NameLCM, false>::executeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0x12dcf686 in /workspace/clickhouse
2021.01.25 03:18:20.616489 [ 155 ] {} <Fatal> BaseDaemon: 9. DB::FunctionBinaryArithmeticWithConstants<DB::(anonymous namespace)::LCMImpl, DB::(anonymous namespace)::NameLCM, false>::executeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0x12dceffc in /workspace/clickhouse
2021.01.25 03:18:20.620086 [ 155 ] {} <Fatal> BaseDaemon: 10. DB::IFunction::executeImplDryRun(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0x11f3f255 in /workspace/clickhouse
2021.01.25 03:18:20.623844 [ 155 ] {} <Fatal> BaseDaemon: 11. DB::DefaultExecutable::executeDryRun(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long) const @ 0x11f44637 in /workspace/clickhouse
2021.01.25 03:18:20.627487 [ 155 ] {} <Fatal> BaseDaemon: 12. DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x129f4ddb in /workspace/clickhouse
2021.01.25 03:18:20.631044 [ 155 ] {} <Fatal> BaseDaemon: 13. DB::ExecutableFunctionAdaptor::execute(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&, std::__1::shared_ptr<DB::IDataType const> const&, unsigned long, bool) const @ 0x129f5dde in /workspace/clickhouse
2021.01.25 03:18:20.632812 [ 155 ] {} <Fatal> BaseDaemon: 14. ./obj-x86_64-linux-gnu/../contrib/boost/boost/smart_ptr/intrusive_ptr.hpp:194: DB::ActionsDAG::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> const&, std::__1::vector<DB::ActionsDAG::Node*, std::__1::allocator<DB::ActionsDAG::Node*> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) @ 0x19f01c11 in /workspace/clickhouse
2021.01.25 03:18:20.634534 [ 155 ] {} <Fatal> BaseDaemon: 15. ./obj-x86_64-linux-gnu/../src/Interpreters/ActionsDAG.cpp:0: DB::ActionsDAG::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::Context const&) @ 0x19f01436 in /workspace/clickhouse
2021.01.25 03:18:20.636651 [ 155 ] {} <Fatal> BaseDaemon: 16. ./obj-x86_64-linux-gnu/../src/Interpreters/ActionsVisitor.cpp:0: DB::ScopeStack::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) @ 0x1a6949af in /workspace/clickhouse
2021.01.25 03:18:20.639110 [ 155 ] {} <Fatal> BaseDaemon: 17. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/string:1444: DB::ActionsMatcher::Data::addFunction(std::__1::shared_ptr<DB::IFunctionOverloadResolver> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) @ 0x1a6a5f83 in /workspace/clickhouse
2021.01.25 03:18:20.641196 [ 155 ] {} <Fatal> BaseDaemon: 18. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/string:1444: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x1a69ca29 in /workspace/clickhouse
2021.01.25 03:18:20.643524 [ 155 ] {} <Fatal> BaseDaemon: 19. ./obj-x86_64-linux-gnu/../src/Interpreters/ActionsVisitor.cpp:0: DB::ActionsMatcher::visit(DB::ASTExpressionList&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x1a6a2370 in /workspace/clickhouse
2021.01.25 03:18:20.645882 [ 155 ] {} <Fatal> BaseDaemon: 20. ./obj-x86_64-linux-gnu/../src/Interpreters/InDepthNodeVisitor.h:43: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x1a6781e2 in /workspace/clickhouse
2021.01.25 03:18:20.647964 [ 155 ] {} <Fatal> BaseDaemon: 21. ./obj-x86_64-linux-gnu/../src/Interpreters/ActionsVisitor.h:160: DB::ExpressionAnalyzer::getRootActions(std::__1::shared_ptr<DB::IAST> const&, bool, std::__1::shared_ptr<DB::ActionsDAG>&, bool) @ 0x1a666060 in /workspace/clickhouse
2021.01.25 03:18:20.650082 [ 155 ] {} <Fatal> BaseDaemon: 22. ./obj-x86_64-linux-gnu/../src/Interpreters/ExpressionAnalyzer.cpp:0: DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0x1a66e34b in /workspace/clickhouse
2021.01.25 03:18:20.652290 [ 155 ] {} <Fatal> BaseDaemon: 23. ./obj-x86_64-linux-gnu/../src/Interpreters/ExpressionAnalyzer.cpp:0: DB::ExpressionAnalysisResult::ExpressionAnalysisResult(DB::SelectQueryExpressionAnalyzer&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, bool, bool, bool, std::__1::shared_ptr<DB::FilterInfo> const&, DB::Block const&) @ 0x1a672667 in /workspace/clickhouse
2021.01.25 03:18:20.654357 [ 155 ] {} <Fatal> BaseDaemon: 24. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:563: DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0x1a3d979e in /workspace/clickhouse
2021.01.25 03:18:20.656465 [ 155 ] {} <Fatal> BaseDaemon: 25. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:457: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&)::$_2::operator()(bool) const @ 0x1a3d0e5c in /workspace/clickhouse
2021.01.25 03:18:20.658411 [ 155 ] {} <Fatal> BaseDaemon: 26. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:463: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0x1a3cc0f3 in /workspace/clickhouse
2021.01.25 03:18:20.660380 [ 155 ] {} <Fatal> BaseDaemon: 27. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:154: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x1a3c9f0a in /workspace/clickhouse
2021.01.25 03:18:20.662436 [ 155 ] {} <Fatal> BaseDaemon: 28. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/memory:2068: std::__1::__unique_if<DB::InterpreterSelectQuery>::__unique_single std::__1::make_unique<DB::InterpreterSelectQuery, std::__1::shared_ptr<DB::IAST> const&, DB::Context&, DB::SelectQueryOptions&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&>(std::__1::shared_ptr<DB::IAST> const&, DB::Context&, DB::SelectQueryOptions&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x1a6c9ed8 in /workspace/clickhouse
2021.01.25 03:18:20.664505 [ 155 ] {} <Fatal> BaseDaemon: 29. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:327: DB::InterpreterSelectWithUnionQuery::buildCurrentChildInterpreter(std::__1::shared_ptr<DB::IAST> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x1a6c7374 in /workspace/clickhouse
2021.01.25 03:18:20.666431 [ 155 ] {} <Fatal> BaseDaemon: 30. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:249: DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x1a6c56ed in /workspace/clickhouse
2021.01.25 03:18:20.668357 [ 155 ] {} <Fatal> BaseDaemon: 31. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/memory:0: std::__1::__unique_if<DB::InterpreterSelectWithUnionQuery>::__unique_single std::__1::make_unique<DB::InterpreterSelectWithUnionQuery, std::__1::shared_ptr<DB::IAST>&, DB::Context&, DB::SelectQueryOptions const&>(std::__1::shared_ptr<DB::IAST>&, DB::Context&, DB::SelectQueryOptions const&) @ 0x1a357556 in /workspace/clickhouse
2021.01.25 03:18:20.869786 [ 155 ] {} <Fatal> BaseDaemon: Calculated checksum of the binary: 8C04440163AA585EE4EDEC0C05CFBEFB. There is no information about the reference checksum.

@qoega

qoega commented Jan 25, 2021

Copy link
Copy Markdown
Member

Build error:

2021-01-25 01:53:42,652 Will build ClickHouse pkg with cmd: 'docker run --network=host --rm --volume=/place/sandbox-data/ramdrive/878396698/ClickHouse/build_output_folder:/output --volume=/place/sandbox-data/ramdrive/878396698/ClickHouse/docker/packager/../..:/build --volume=/place/sandbox-data/ramdrive/878396698/local_ccache:/ccache  -e DEB_CC=clang-11 -e DEB_CXX=clang++-11 -e BUILD_TYPE=debug -e CCACHE_DIR=/ccache -e CCACHE_BASEDIR=/build -e CCACHE_NOHASHDIR=true -e CCACHE_COMPILERCHECK=content -e CCACHE_MAXSIZE=15G -e ENABLE_TESTS=1 -e BINARY_OUTPUT=tests -e NINJA_FLAGS=-k0 -e VERSION_STRING='21.2.1.5792' -e AUTHOR='clickhouse' -e CMAKE_FLAGS="$CMAKE_FLAGS -DADD_GDB_INDEX_FOR_GOLD=1 -DLINKER_NAME=lld -DENABLE_TESTS=1 -DUSE_GTEST=1 -DENABLE_CLANG_TIDY=1 -DWITH_COVERAGE=1"  yandex/clickhouse-deb-builder:latest'
...

2021-01-25 00:01:24 FAILED: src/Functions/CMakeFiles/clickhouse_functions.dir/lcm.cpp.o 
2021-01-25 00:01:24 /usr/bin/ccache /usr/bin/cmake -E __run_co_compile --launcher="prlimit;--as=10000000000;--data=5000000000;--cpu=600" --tidy=/usr/bin/clang-tidy-11 --source=../src/Functions/lcm.cpp -- /usr/bin/clang++-11  -DAWS_SDK_VERSION_MAJOR=1 -DAWS_SDK_VERSION_MINOR=7 -DAWS_SDK_VERSION_PATCH=231 -DBOOST_ASIO_STANDALONE=1 -DCARES_STATICLIB -DENABLE_MULTITARGET_CODE=1 -DENABLE_OPENSSL_ENCRYPTION -DHAS_SUGGEST_DESTRUCTOR_OVERRIDE -DHAS_SUGGEST_OVERRIDE -DLZ4_DISABLE_DEPRECATE_WARNINGS=1 -DPOCO_ENABLE_CPP11 -DPOCO_HAVE_FD_EPOLL -DPOCO_OS_FAMILY_UNIX -DSTD_EXCEPTION_HAS_STACK_TRACE=1 -DUNALIGNED_OK -DUSE_FASTMEMCPY=1 -DUSE_HYPERSCAN=1 -DUSE_REPLXX=1 -DUSE_XXHASH=1 -DWITH_COVERAGE=1 -DWITH_GZFILEOP -DX86_64 -DZLIB_COMPAT -D__CLANG_SUPPORT_DYN_ANNOTATION__ -I../contrib/sentry-native/include -Iincludes/configs -I../contrib/cityhash102/include -I../contrib/libfarmhash -I../src -Isrc -Isrc/Core/include -I../base/common/.. -Ibase/common/.. -I../contrib/FastMemcpy -I../contrib/cctz/include -Icontrib/zlib-ng -I../contrib/zlib-ng -I../base/pcg-random/. -I../contrib/aws-c-common/include -I../contrib/aws-c-event-stream/include -Icontrib/aws-s3-cmake/include -I../contrib/consistent-hashing -I../base/mysqlxx/.. -I../contrib/mariadb-connector-c/include -Icontrib/mariadb-connector-c/include -Icontrib/grpc/third_party/cares/cares -I../contrib/grpc/third_party/cares/cares -I../contrib/abseil-cpp -I../contrib/libuv/include -I../contrib/libpq -I../contrib/libpq/include -I../contrib/libmetrohash/src -I../contrib/murmurhash/include -I../contrib/lz4/lib -isystem ../contrib/llvm/llvm/include -isystem contrib/llvm/llvm/include -isystem ../contrib/sparsehash-c11 -isystem ../contrib/fastops -isystem ../contrib/h3/src/h3lib/include -isystem ../contrib/rapidjson/include -isystem ../contrib/libcxx/include -isystem ../contrib/libcxxabi/include -isystem ../contrib/libunwind/include -isystem ../contrib/base64 -isystem ../contrib/fast_float/include -isystem ../contrib/msgpack-c/include -isystem ../contrib/aws/aws-cpp-sdk-s3/include -isystem ../contrib/aws/aws-cpp-sdk-core/include -isystem ../contrib/xz/src/liblzma/api -isystem ../contrib/zstd/lib -isystem ../contrib/re2 -isystem ../contrib/boost -isystem ../contrib/poco/Net/include -isystem ../contrib/poco/Foundation/include -isystem ../contrib/poco/NetSSL_OpenSSL/include -isystem ../contrib/poco/Crypto/include -isystem ../contrib/boringssl/include -isystem ../contrib/poco/Util/include -isystem ../contrib/poco/JSON/include -isystem ../contrib/poco/XML/include -isystem ../contrib/replxx/include -isystem ../contrib/fmtlib-cmake/../fmtlib/include -isystem ../contrib/double-conversion -isystem ../contrib/dragonbox/include -isystem contrib/re2_st -isystem ../contrib/croaring/cpp -isystem ../contrib/croaring/include -isystem ../contrib/libpqxx/include -isystem ../contrib/rocksdb/include -isystem ../contrib/orc/c++/include -isystem contrib/orc/c++/include -isystem ../contrib/libhdfs3/include -isystem ../contrib/miniselect/include -isystem ../contrib/pdqsort -isystem ../contrib/AMQP-CPP/include -isystem ../contrib/grpc/include -isystem ../contrib/protobuf/src -isystem src/Server/grpc_protos -isystem ../contrib/libdivide/. -isystem ../contrib/icu/icu4c/source/i18n -isystem ../contrib/icu/icu4c/source/common -isystem contrib/h3/src/h3lib/include -isystem ../contrib/hyperscan/src -isystem ../contrib/simdjson/include -isystem ../contrib/stats/include -isystem ../contrib/gcem/include -isystem ../contrib/libc-headers/x86_64-linux-gnu -isystem ../contrib/libc-headers -g -O2 -fdebug-prefix-map=/build=. -specs=/usr/share/dpkg/no-pie-compile.specs -Wdate-time -fdiagnostics-color=always -std=gnu++2a -fsized-deallocation  -gdwarf-aranges -pipe -msse4.1 -msse4.2 -mpopcnt -fprofile-instr-generate -fcoverage-mapping   -Wall -Wno-unused-command-line-argument  -fdiagnostics-absolute-paths -fexperimental-new-pass-manager -Werror -Wextra -Wpedantic -Wno-vla-extension -Wno-zero-length-array -Wno-c11-extensions -Wcomma -Wconditional-uninitialized -Wcovered-switch-default -Wdeprecated -Wembedded-directive -Wempty-init-stmt -Wextra-semi-stmt -Wextra-semi -Wgnu-case-range -Winconsistent-missing-destructor-override -Wnewline-eof -Wold-style-cast -Wrange-loop-analysis -Wredundant-parens -Wreserved-id-macro -Wshadow-field -Wshadow-uncaptured-local -Wshadow -Wstring-plus-int -Wundef -Wunreachable-code-return -Wunreachable-code -Wunused-exception-parameter -Wunused-macros -Wunused-member-function -Wzero-as-null-pointer-constant -Weverything -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-c99-extensions -Wno-conversion -Wno-ctad-maybe-unsupported -Wno-deprecated-dynamic-exception-spec -Wno-disabled-macro-expansion -Wno-documentation-unknown-command -Wno-double-promotion -Wno-exit-time-destructors -Wno-float-equal -Wno-global-constructors -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-nested-anon-types -Wno-packed -Wno-padded -Wno-return-std-move-in-c++11 -Wno-shift-sign-overflow -Wno-sign-conversion -Wno-switch-enum -Wno-undefined-func-template -Wno-unused-template -Wno-vla -Wno-weak-template-vtables -Wno-weak-vtables -g -O0 -g3 -ggdb3 -fno-inline  -D_LIBCPP_DEBUG=0   -D OS_LINUX -nostdinc++ -pthread -MD -MT src/Functions/CMakeFiles/clickhouse_functions.dir/lcm.cpp.o -MF src/Functions/CMakeFiles/clickhouse_functions.dir/lcm.cpp.o.d -o src/Functions/CMakeFiles/clickhouse_functions.dir/lcm.cpp.o -c ../src/Functions/lcm.cpp
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:65:40: error: 'signed char' to 'Int' (aka '__int128') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24             Int a_u = static_cast<Int>(a);
2021-01-25 00:01:24                                        ^
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:65:40: error: 'signed char' to 'Int' (aka 'int') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:65:40: error: 'signed char' to 'Int' (aka 'long') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:65:40: error: 'signed char' to 'Int' (aka 'short') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:66:40: error: 'signed char' to 'Int' (aka '__int128') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24             Int b_u = static_cast<Int>(b);
2021-01-25 00:01:24                                        ^
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:66:40: error: 'signed char' to 'Int' (aka 'int') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:66:40: error: 'signed char' to 'Int' (aka 'long') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 /build/obj-x86_64-linux-gnu/../src/Functions/lcm.cpp:66:40: error: 'signed char' to 'Int' (aka 'short') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse,-warnings-as-errors]
2021-01-25 00:01:24 82934 warnings generated.
2021-01-25 00:01:24 Suppressed 82912 warnings (82911 in non-user code, 1 with check filters).
2021-01-25 00:01:24 Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
2021-01-25 00:01:24 8 warnings treated as errors

@azat

azat commented Jan 25, 2021

Copy link
Copy Markdown
Member Author

Fuzzer fail is related

Not related, but yes this is just one more UB case, will address it too

@azat

azat commented Jan 25, 2021

Copy link
Copy Markdown
Member Author

../src/Functions/lcm.cpp:56:77: runtime error: nan is outside the range of representable values of type 'long'

There are other issues with float, seems that lcm/gcd should not be allowed for floats, objections?

@alexey-milovidov

Copy link
Copy Markdown
Member

There are other issues with float, seems that lcm/gcd should not be allowed for floats, objections?

No objections.

@robot-clickhouse robot-clickhouse added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Jan 25, 2021
@azat
azat force-pushed the UBsan-report-fixes-v2 branch from 2089f4d to 8edfb4e Compare January 25, 2021 22:09
@azat
azat force-pushed the UBsan-report-fixes-v2 branch from 8edfb4e to d35ff7d Compare January 25, 2021 22:13
@azat

azat commented Jan 26, 2021 •

Copy link
Copy Markdown
Member Author

AST fuzzer (UBSan) — OK

Finally (d35ff7d553cf99b5acd4c2e88f17633cad9f351c - https://clickhouse-test-reports.s3.yandex.net/19532/d35ff7d553cf99b5acd4c2e88f17633cad9f351c/fuzzer_ubsan/report.html)

But I need to add missing #pragma once ...

Changelog:
- Check against INT64_MIN/INT64_MAX
- Check against std::numeric_limits<>::min/max
- Move common code into separate header - GCDLCMImpl.h
- Forbid floats

UBsan report [1].

  [1]: https://clickhouse-test-reports.s3.yandex.net/19466/cb30a02540a0f223df6668c5f88ff84aa666ff54/fuzzer_ubsan/report.html#fail1
@azat
azat force-pushed the UBsan-report-fixes-v2 branch from d35ff7d to 27a5794 Compare January 26, 2021 05:34
@azat azat changed the title UBsan reports fixes Forbid lcm/gcd for floats (and few UBsan reports fixes) Jan 26, 2021
@alexey-milovidov
alexey-milovidov merged commit e8dedbf into ClickHouse:master Jan 26, 2021
@azat
azat deleted the UBsan-report-fixes-v2 branch January 26, 2021 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants