Skip to content

[UBSAN] Duration type overflow when enable asan with clang 20.1.3 #3528

@owent

Description

@owent

Describe your environment

OS: Linux x86_64
Compiler: clang 20.1.3 with libc++(enable asan)

Additional context

Don't know why trigger ubsan when enable asan, but it's still a problem.

Process 3705566 stopped
* thread #1, name = 'otlp_http_log_r', stop reason = Signed integer overflow
    frame #0: 0x0000555555771fa0 otlp_http_log_record_exporter_test`__ubsan_on_report at ubsan_monitor.cpp:40:40
Running expression: 
struct {
warning: ubsan_monitor.cpp: source file checksum mismatch between line table (d86be2442566cf10902db54006f9794e) and file on disk ()
(lldb) bt
* thread #1, name = 'otlp_http_log_r', stop reason = Signed integer overflow
  * frame #0: 0x0000555555771fa0 otlp_http_log_record_exporter_test`__ubsan_on_report at ubsan_monitor.cpp:40:40
    frame #1: 0x000055555576bfab otlp_http_log_record_exporter_test`::~Diag() at ubsan_diag.cpp:360:29
    frame #2: 0x000055555576e087 otlp_http_log_record_exporter_test`::handleIntegerOverflowImpl<__ubsan::Value>() at ubsan_handlers.cpp:227:3
    frame #3: 0x000055555576e2b2 otlp_http_log_record_exporter_test`__ubsan_handle_mul_overflow_abort at ubsan_handlers.cpp:247:1
    frame #4: 0x00007ffff7b27b79 libexporters_Sotlp_Slibotlp_Uhttp_Uclient.so`std::__2::chrono::__duration_cast<std::__2::chrono::duration<long long, std::__2::ratio<1l, 1000000l>>, std::__2::chrono::duration<long long, std::__2::ratio<1l, 1000000000l>>, std::__2::ratio<1000l, 1l>, false, true>::operator()[abi:ne200100](this=0x00007bffece71820, __fd=0x00007bffed0e8ce0) const at duration.h:91:79
    frame #5: 0x00007ffff7b0fa51 libexporters_Sotlp_Slibotlp_Uhttp_Uclient.so`std::__2::chrono::duration<long long, std::__2::ratio<1l, 1000000000l>> std::__2::chrono::duration_cast[abi:ne200100]<std::__2::chrono::duration<long long, std::__2::ratio<1l, 1000000000l>>, long long, std::__2::ratio<1l, 1000000l>, 0>(__fd=0x00007bffed0e8ce0) at duration.h:106:10
    frame #6: 0x00007ffff7b525b0 libexporters_Sotlp_Slibotlp_Uhttp_Uclient.so`std::__2::chrono::duration<long long, std::__2::ratio<1l, 1000000000l>>::duration[abi:ne200100]<long long, std::__2::ratio<1l, 1000000l>, 0>(this=0x00007bffecfd52a0, __d=0x00007bffed0e8ce0) at duration.h:219:16
    frame #7: 0x00007ffff1354c8d libexternal_S_Umain~_Urepo_Urules~io_Uopentelemetry_Ucpp_Ssdk_Ssrc_Slogs_Sliblogs.so`auto std::__2::chrono::operator<=>[abi:ne200100]<long long, std::__2::ratio<1l, 1000000l>, long long, std::__2::ratio<1l, 1000000000l>>(__lhs=0x00007bffed0e8ce0, __rhs=0x00007bffed0e8c40) at duration.h:384:10
    frame #8: 0x00007ffff143e272 libexternal_S_Umain~_Urepo_Urules~io_Uopentelemetry_Ucpp_Ssdk_Ssrc_Slogs_Sliblogs.so`opentelemetry::v1::sdk::logs::MultiLogRecordProcessor::ForceFlush(this=0x00007c2fee0e6ee0, timeout=9223372036854775807 µs) at multi_log_record_processor.cc:86:37
    frame #9: 0x00007ffff138e8fa libexternal_S_Umain~_Urepo_Urules~io_Uopentelemetry_Ucpp_Ssdk_Ssrc_Slogs_Sliblogs.so`opentelemetry::v1::sdk::logs::LoggerContext::ForceFlush(this=0x00007cafee0e05d8, timeout=9223372036854775807 µs) at logger_context.cc:57:22
    frame #10: 0x00007ffff13be3b2 libexternal_S_Umain~_Urepo_Urules~io_Uopentelemetry_Ucpp_Ssdk_Ssrc_Slogs_Sliblogs.so`opentelemetry::v1::sdk::logs::LoggerProvider::ForceFlush(this=0x00007c7fee0e5b20, timeout=9223372036854775807 µs) at logger_provider.cc:139:20
    frame #11: 0x000055555577df03 otlp_http_log_record_exporter_test`opentelemetry_ecosystem::v1::exporter::otlp::OtlpHttpLogExporterTestPeer::ExportJsonIntegrationTest(this=0x00007c1fee0e0350, is_async=false) at otlp_http_log_record_exporter_test.cc:176:15
    frame #12: 0x0000555555772975 otlp_http_log_record_exporter_test`opentelemetry_ecosystem::v1::exporter::otlp::OtlpHttpLogExporterTestPeer_ExportJsonIntegrationTestSync_Test::TestBody(this=0x00007c1fee0e0350) at otlp_http_log_record_exporter_test.cc:277:70
    frame #13: 0x00007ffff0d56bdc libexternal_Sgoogletest~_Slibgtest.so`void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(object=0x00007c1fee0e0350, method=0x00000000000000000000000000000021, location="the test body") at gtest.cc:2664:10
    frame #14: 0x00007ffff0cf7a20 libexternal_Sgoogletest~_Slibgtest.so`void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(object=0x00007c1fee0e0350, method=0x00000000000000000000000000000021, location="the test body") at gtest.cc:2700:14
    frame #15: 0x00007ffff0cad018 libexternal_Sgoogletest~_Slibgtest.so`testing::Test::Run(this=0x00007c1fee0e0350) at gtest.cc:2739:5
    frame #16: 0x00007ffff0caeb07 libexternal_Sgoogletest~_Slibgtest.so`testing::TestInfo::Run(this=0x00007d0fee0e8240) at gtest.cc:2885:11
    frame #17: 0x00007ffff0cb05fe libexternal_Sgoogletest~_Slibgtest.so`testing::TestSuite::Run(this=0x00007d0fee0e8380) at gtest.cc:3063:30
    frame #18: 0x00007ffff0cd5843 libexternal_Sgoogletest~_Slibgtest.so`testing::internal::UnitTestImpl::RunAllTests(this=0x00007d5fee0e1880) at gtest.cc:6054:44
    frame #19: 0x00007ffff0d5ea5c libexternal_Sgoogletest~_Slibgtest.so`bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(object=0x00007d5fee0e1880, method=(libexternal_Sgoogletest~_Slibgtest.so`testing::internal::UnitTestImpl::RunAllTests() at gtest.cc:5909), location="auxiliary test code (environments or event listeners)") at gtest.cc:2664:10
    frame #20: 0x00007ffff0cfd6cf libexternal_Sgoogletest~_Slibgtest.so`bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(object=0x00007d5fee0e1880, method=(libexternal_Sgoogletest~_Slibgtest.so`testing::internal::UnitTestImpl::RunAllTests() at gtest.cc:5909), location="auxiliary test code (environments or event listeners)") at gtest.cc:2700:14
    frame #21: 0x00007ffff0cd4274 libexternal_Sgoogletest~_Slibgtest.so`testing::UnitTest::Run(this=0x00007ffff0e65e40) at gtest.cc:5594:10
    frame #22: 0x00007ffff1636ac0 libexternal_Sgoogletest~_Slibgtest_Umain.so`RUN_ALL_TESTS() at gtest.h:2334:73
    frame #23: 0x00007ffff16369a7 libexternal_Sgoogletest~_Slibgtest_Umain.so`main(argc=1, argv=0x00007fffffffdf18) at gmock_main.cc:71:10
    frame #24: 0x00007fffeec082a0 libc.so.6`__libc_start_call_main + 128
    frame #25: 0x00007fffeec08359 libc.so.6`__libc_start_main@@GLIBC_2.34 + 137
    frame #26: 0x000055555568bd05 otlp_http_log_record_exporter_test`_start + 37
(lldb) quit

/opt/llvm-20.1/bin/../include/c++/v1/__chrono/duration.h:91:79: runtime error: signed integer overflow: 9221619975911019105 * 1000 cannot be represented in type '_Ct' (aka 'long long')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/llvm-20.1/bin/../include/c++/v1/__chrono/duration.h:91:79 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions