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

Signed overflow in InmemAddressRepository::upsertAddresses #281

Open
Harrm opened this issue Nov 28, 2024 · 0 comments
Open

Signed overflow in InmemAddressRepository::upsertAddresses #281

Harrm opened this issue Nov 28, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Harrm
Copy link
Contributor

Harrm commented Nov 28, 2024

Summary

The following line

auto expires_at = Clock::now() + ttl;

Provokes a signed overflow, which is reported by UBSAN, if TTL is larger than several hundred years. In particular, libp2p::peer::ttl::kPermanent does trigger the overflow.
https://godbolt.org/z/ahcdE5Msq - an MRE.
Permanent ttl should be expressed in some valid way, and probably some type safer than chrono::milliseconds, that silently overflows, should be used in the interface.

Expected behavior

Expected defined behaviour.

Actual behavior

Actual behaviour is undefined due to signed overflow.

Relevant log output

/usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:227:38: runtime error: signed integer overflow: 9223372036854775807 * 1000000 cannot be represented in type 'long'
24.11.28 14:52:30.896390  telemetry        Info      TelemetryConnection#1  Connection established
    #0 0x61348f7c8555 in std::chrono::duration<long, std::ratio<1l, 1000000000l>> std::chrono::__duration_cast_impl<std::chrono::duration<long, std::ratio<1l, 1000000000l>>, std::ratio<1000000l, 1l>, long, false, true>::__cast<long, std::ratio<1l, 1000l>>(std::chrono::duration<long, std::ratio<1l, 1000l>> const&) /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:227:38
    #1 0x61348f7c8250 in std::enable_if<__is_duration<std::chrono::duration<long, std::ratio<1l, 1000000000l>>>::value, std::chrono::duration<long, std::ratio<1l, 1000000000l>>>::type std::chrono::duration_cast<std::chrono::duration<long, std::ratio<1l, 1000000000l>>, long, std::ratio<1l, 1000l>>(std::chrono::duration<long, std::ratio<1l, 1000l>> const&) /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:289:11
    #2 0x61348fa7e150 in std::chrono::duration<long, std::ratio<1l, 1000000000l>>::duration<long, std::ratio<1l, 1000l>, void>(std::chrono::duration<long, std::ratio<1l, 1000l>> const&) /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:582:10
    #3 0x61348fea5010 in std::common_type<std::chrono::duration<long, std::ratio<1l, 1000000000l>>, std::chrono::duration<long, std::ratio<1l, 1000l>>>::type std::chrono::operator+<long, std::ratio<1l, 1000000000l>, long, std::ratio<1l, 1000l>>(std::chrono::duration<long, std::ratio<1l, 1000000000l>> const&, std::chrono::duration<long, std::ratio<1l, 1000l>> const&) /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:702:36
    #4 0x61348fea215b in std::chrono::time_point<std::chrono::_V2::steady_clock, std::common_type<std::chrono::duration<long, std::ratio<1l, 1000000000l>>, std::chrono::duration<long, std::ratio<1l, 1000l>>>::type> std::chrono::operator+<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>, long, std::ratio<1l, 1000l>>(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>> const&, std::chrono::duration<long, std::ratio<1l, 1000l>> const&) /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/chrono.h:1107:47
    #5 0x6134996c8f07 in libp2p::peer::InmemAddressRepository::upsertAddresses(libp2p::peer::PeerId const&, std::span<libp2p::multi::Multiaddress const, 18446744073709551615ul>, std::chrono::duration<long, std::ratio<1l, 1000l>>) /home/harrm/.hunter/_Base/3fb5849/417772a/9a920dc/Build/libp2p/Source/src/peer/address_repository/inmem_address_repository.cpp:103:36
...

Possible Solution

No response

Version

Commit c96d45f

Would you like to work on fixing this bug ?

Yes

@Harrm Harrm added bug Something isn't working good first issue Good for newcomers labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant