rocksdb/options
Hui Xiao c76cacc696 Fix overflow in MultiplyCheckOverflow() due to std::numeric_limits<uint64_t>::max()'s promotion to double (#14132)
Summary:
**Context/Summary:**
Due to double's 53-bit mantissa limitation, large uint64_t values lose precision when converted to double. Value equals to or smaller than UINT64_MAX (but greater than 2^64 - 1024) round up to 2^64 since rounding up results in less error than rounding down, which exceeds UINT64_MAX. `std::numeric_limits<uint64_t>::max() / op1 < op2` won't catch those cases. Casting such out-of-range doubles back to uint64_t causes undefined behavior. T

Pull Request resolved: https://github.com/facebook/rocksdb/pull/14132
UndefinedBehaviorSanitizer: undefined-behavior options/cf_options.cc:1087:32 in
```
before the fix but not after.

Test Plan:
```
COMPILE_WITH_ASAN=1 COMPILE_WITH_UBSAN=1 CC=clang-18 CXX=clang++-18 ROCKSDB_DISABLE_ALIGNED_NEW=1 USE_CLANG=1 make V=1 -j55 db_stress

python3 tools/db_crashtest.py --simple blackbox --compact_range_one_in=5 --target_file_size_base=9223372036854775807 // Half of std::numeric_limits<uint64_t>::max()
```
It fails with
```
stderr:
 options/cf_options.cc:1087:32: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long'

Reviewed By: pdillinger

Differential Revision: D87434936

Pulled By: hx235

fbshipit-source-id: 65563edf9faf732410bdba8b9e4b7fd61b958169
2025-11-19 16:25:53 -08:00
..
cf_options.cc Fix overflow in MultiplyCheckOverflow() due to std::numeric_limits<uint64_t>::max()'s promotion to double (#14132) 2025-11-19 16:25:53 -08:00
cf_options.h Add option to verify block checksums of output files (#14103) 2025-11-07 14:22:00 -08:00
configurable.cc Preliminary support for custom compression algorithms (#13659) 2025-06-16 14:19:03 -07:00
configurable_helper.h Fix race to make BlockBasedTableOptions effectively mutable (#13082) 2024-10-25 10:24:54 -07:00
configurable_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
configurable_test.h Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
customizable.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
customizable_test.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
db_options.cc Auto-tune manifest file size (#14076) 2025-11-07 09:04:52 -08:00
db_options.h Auto-tune manifest file size (#14076) 2025-11-07 09:04:52 -08:00
offpeak_time_info.cc Mark more files for periodic compaction during offpeak (#12031) 2023-11-06 11:43:59 -08:00
offpeak_time_info.h Fix build on alpine 3.19 (#12345) 2024-02-12 11:24:56 -08:00
options.cc Introduce tail estimation to prevent oversized compaction files (#14051) 2025-11-05 20:00:00 -08:00
options_helper.cc Add option to verify block checksums of output files (#14103) 2025-11-07 14:22:00 -08:00
options_helper.h Support recompress-with-CompressionManager in sst_dump (#13783) 2025-07-18 14:22:29 -07:00
options_parser.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
options_parser.h Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
options_settable_test.cc Add option to verify block checksums of output files (#14103) 2025-11-07 14:22:00 -08:00
options_test.cc Add option to verify block checksums of output files (#14103) 2025-11-07 14:22:00 -08:00