Skip to content

fix(utils): use a size_t shift operand in ceil_log2 - #247

Merged
gouyt13 merged 1 commit into
dev/0.9from
fix/ceil-log2-shift
Nov 18, 2026
Merged

gouyt13 merged 1 commit into
dev/0.9from
fix/ceil-log2-shift

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 18, 2026

Copy link
Copy Markdown
Member

Summary

ceil_log2 in include/rabitqlib/utils/tools.hpp shifted 1UL, which is 32 bits on LLP64 (64-bit Windows). For inputs of 2^32 or more the shift count reaches 32, which is undefined. The shift operand is now size_t{1}. No library code calls ceil_log2, so nothing in the library changes behavior.

Reported in #246.

Testing

Local, Linux x86-64, clang, Release, core-only build, RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF:

  • New ToolsTest.CeilLog2RoundsUpAcrossSizeTWidth checks 0, 1, 3, every 2^k and 2^k + 1 across the size_t width, and SIZE_MAX.
  • ctest: 156 of 156 passed.
  • With the shift operand changed to uint32_t{1} to mimic the LLP64 width, the new test fails from 2^32 onward (for example 33 instead of 32); it passes again with the fix. On LP64 the old 1UL is already 64 bits, so the test cannot fail there for the original code.
  • ./scripts/check-format.sh, git diff --check.
  • LLP64 check without MSVC: with clang++-23 --target=x86_64-pc-windows-msvc -fsyntax-only, a constexpr copy of the old expression fails static_assert(ceil_log2(2^32) == 32) with shift count 32 >= width of type 'unsigned long' (32 bits); the new expression passes for 2^32 and SIZE_MAX.
  • Not run on Windows: Windows CI builds only the Python package, not the C++ tests, so the new test does not guard the LLP64 case in CI.

`1UL` is 32 bits on LLP64 (64-bit Windows), so ceil_log2 shifted past the
operand width for inputs of 2^32 or more. No library code calls it.

Reported in #246.
@github-actions github-actions Bot added the release:fixed Release category managed from the PR title label Nov 18, 2026
@gouyt13
gouyt13 merged commit e19e749 into dev/0.9 Nov 18, 2026
35 checks passed
@gouyt13
gouyt13 deleted the fix/ceil-log2-shift branch November 18, 2026 11:34
TamimEhsan pushed a commit to TamimEhsan/khorgosh that referenced this pull request Nov 28, 2026
The 0.8 to 0.9 section now lists, next to the int64 IDs and index format 2,
what only the release notes mentioned: HNSW-routed IVF indexes no longer
write a .hnsw sidecar, load raises rabitqlib.FormatError (a RuntimeError
and ValueError subclass), the index classes are plain extension classes
(pybind11 TypeError, no inspect.signature), and an invalid argument may be
reported before a wrong state. The release notes add the ceil_log2 fix from
VectorDB-NTU#247.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fixed Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant