Signed overflow in InmemAddressRepository::upsertAddresses
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- cpp
- 领域
- networking
调研方向
从 src/peer/address_repository/inmem_address_repository.cpp 中链接的行开始,检查 TTL 是如何加到 steady-clock 时间点上的。使用提供的 Godbolt MRE 和 UBSAN 报告重现溢出;完成标准是永久 TTL 值和非常大的 TTL 值在不发生 signed overflow 的情况下具有明确定义的行为,并考虑到任何接口变更。
由索引模型根据 Issue 内容生成。
描述
Summary
The following line
https://github.com/libp2p/cpp-libp2p/blob/093a3f7b0c9f45300f2ec88cc2bfabe083c5d2f2/src/peer/address_repository/inmem_address_repository.cpp#L103
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 c96d45f792fafd6970a7e37ec816b02a9167e2b6
Would you like to work on fixing this bug ?
Yes
- 主要语言
- C++
- 星标
- 493
- 派生
- 131
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
libp2p/cpp-libp2p 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
libp2p/cpp-libp2p#351 ·
-
难度 4/5 3-5 天 新手友好度 48/100
libp2p/cpp-libp2p#347 ·
-
难度 4/5 3-5 天 新手友好度 35/100
libp2p/cpp-libp2p#341 ·
-
Lack of signedPeerRecord Validation in C++ IdentifyMessageProcessor Leads to Address Injection可能已有人在做 @alienx5499 于 318 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
libp2p/cpp-libp2p#332 ·
-
难度 4/5 3-5 天 新手友好度 45/100
libp2p/cpp-libp2p#324 · 1 条评论 · 1 个 reaction ·
查看 libp2p/cpp-libp2p 的全部 Issue
相似的 Issue
-
ai_p2
难度 2/5 1-3 小时 新手友好度 68/100
ClickHouse/ClickHouse#125522 ·
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
open-telemetry/opentelemetry-cpp#4697 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 73/100
FujiNetWIFI/fujinet-firmware#1921 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
azerothcore/azerothcore-wotlk#28108 ·
维护者通常 1 天内回复