mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #4365] [Bug]: byte_size parsing accepts non-finite values ("inf"/"nan") triggering UB in the double-to-uint64_t cast, and "infinite" does not round-trip through byte_size_to_string #1094
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#1094
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xiaodu55 on GitHub (Sep 28, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/4365
Bug Report
Version: current
main(d9152a47, 2026-09-28),mooncake-store/include/common/byte_size.hEnvironment: Ubuntu 24.04 x86_64, g++ 13.3, UBSan (
-fsanitize=undefined,float-cast-overflow). The wrong results are platform-dependent (see the aarch64 note below).Summary
try_string_to_byte_size()parses the numeric part withstd::stod(), which happily parses the non-finite literals"inf","infinity"and"nan". The result is only guarded byvalue < 0and then converted withstatic_cast<uint64_t>(value). Casting a non-finitedoubleto an integer type is undefined behavior (C++17 [conv.fpint]), and the observed result is platform-dependent:try_string_to_byte_size("inf")returns 0 (UBSan reportsbyte_size.h:67: runtime error: inf is outside the range of representable values of type 'long unsigned int'), andtry_string_to_byte_size("nan")returns 9223372036854775808 (2^63).Why it matters (callers)
All four call sites feed user-controlled configuration strings through this helper:
mooncake-store/src/real_client_main.cpp:134-135— CLI flags--global_segment_size/--local_buffer_size.--global_segment_size=infsilently becomes 0 on x86_64 instead of being rejected (and UINT64_MAX on arm64).mooncake-store/src/config/mmap_arena_config.cpp:63—MC_MMAP_ARENA_POOL_SIZE:"nan"parses to 2^63, passes theparsed > 0check, and sets a bogus ~8 EiB pool size instead of falling back to the default with a warning.mooncake-store/src/config/hugepage_config.cpp:40—MC_STORE_HUGEPAGE_SIZE.mooncake-store/src/real_client.cpp:1357— env-based parsing.The established contract for invalid input in this helper is "return
std::nullopt" (that is what-5,16XB, etc. do). Non-finite values bypass that contract and additionally invoke UB.Second, related inconsistency:
try_string_to_byte_size("infinite")returnsUINT64_MAX, butbyte_size_to_string()only prints"infinite"forINT64_MAX, so the parse → print round trip yields"16777216.00 TB"instead of"infinite".INT64_MAXis used as an "infinite" sentinel in several places (e.g.allocator.cpp,master_service.cpp), sobyte_size_to_string()should recognize both sentinels.Minimal repro
Output (x86_64, g++ 13.3,
-fsanitize=undefined,float-cast-overflow):Proposed fix
try_string_to_byte_size(): reject non-finite parsed values (!std::isfinite(value)→std::nullopt), keeping the existing "nullopt on invalid input" contract.byte_size_to_string(): print"infinite"for bothUINT64_MAXandINT64_MAX, without the implementation-definedint64_tround-trip cast.inf/infinity/nan/1e999and theinfiniteround trip inbyte_size_test.cpp.I have the fix and tests ready locally and will submit a PR right away.
Before submitting...
@xiaodu55 commented on GitHub (Sep 28, 2026):
I'll take this one — fix and tests are ready locally; PR to follow shortly.
@github-actions[bot] commented on GitHub (Sep 28, 2026):
Thanks for opening this issue, @xiaodu55!
203964531A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide