fix(vector): fix 4 bugs causing Windows segfault + silent index corruption (HNSW)#21
Closed
chiangchenghsin-hash wants to merge 3 commits into
Closed
Conversation
…eation on Windows
…eation on Windows
…UMMY_CHECKPOINT_TRANSACTION)
Contributor
|
Moved to #23 with CI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 4 bugs in the VECTOR extension that cause SEGFAULT (0xC0000005) on Windows and silent index corruption on all platforms. Verified on Windows 11 x64 with MSVC 19.50, LadybugDB 0.18.0.
Supersedes #499 (closed without fix — bug still present in 0.18.0 source).
Bugs Fixed
Bug 1: MSVC const-correctness —
create_hnsw_index.cpp:60NodeTable::getNumTotalRows()is non-const. MSVC rejectsconst auto& tablecalling it (error C2662). Clang/GCC tolerate it, so this only blocks Windows source builds.Bug 2: Stale table cardinality —
create_hnsw_index.cpp:64getStats(transaction).getTableCard()returns a statistics snapshot that can be 0 or stale during uncommitted transactions / WAL replay. This causednumNodes=0→ HNSW graph allocated with wrong size.Bug 3:
DUMMY_CHECKPOINT_TRANSACTIONinfinalize()—hnsw_index.cpp:672OnDiskHNSWIndex::finalize()queried row count via the static dummy transaction, which returns 0 in non-checkpoint contexts. This madefinalize()silently skip incremental writes — newly inserted nodes were never indexed. This is a platform-agnostic correctness bug (Linux silently loses index coverage; Windows additionally crashes downstream).void OnDiskHNSWIndex::finalize(main::ClientContext* context) { auto& hnswStorageInfo = storageInfo->cast<HNSWStorageInfo>(); - const auto numTotalRows = nodeTable.getNumTotalRows(&DUMMY_CHECKPOINT_TRANSACTION); + auto transaction = Transaction::Get(*context); + const auto numTotalRows = nodeTable.getNumTotalRows(transaction); if (numTotalRows == hnswStorageInfo.numCheckpointedNodes) { return; } - auto transaction = Transaction::Get(*context);Bug 4:
INVALID_OFFSETout-of-bounds —hnsw_rel_batch_insert.cpp:127Uninitialized CSR neighbor slots are marked
INVALID_OFFSET. The batch insert loop passed them tographToNodeOffset()without filtering → out-of-bounds access →0xC0000005on Windows (Linux silently writes garbage).for (const auto neighbourGraphOffset : neighbours) { + if (neighbourGraphOffset == common::INVALID_OFFSET) { + continue; + } const auto neighbourNodeOffset = selectionMap.graphToNodeOffset(neighbourGraphOffset);Why these matter beyond Windows
Bugs 2, 3, and 4 are platform-agnostic correctness bugs. On Linux they don't crash (glibc's tolerant malloc) but silently produce:
Verification
Built from source on Windows 11 with MSVC 19.50 + CMake Ninja (
BUILD_EXTENSIONS=vector). End-to-end test:Before the fix:
LOAD VECTOR→STATUS_ACCESS_VIOLATION(deterministic crash, exit -1073741819).Related