Skip to content

fix(dense): reject rename and batch remove on immutable viewed index - #841

Closed
Tyagiquamar wants to merge 1 commit into
unum-cloud:mainfrom
Tyagiquamar:fix/835-view-rename-batch-remove-immutable
Closed

Tyagiquamar wants to merge 1 commit into
unum-cloud:mainfrom
Tyagiquamar:fix/835-view-rename-batch-remove-immutable

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

Fixes #835 by preventing rename and batch remove operations on immutable viewed indexes from attempting to mutate read-only memory mappings, returning an informative error instead of crashing the process with SIGBUS.

Root Cause & Problem

In include/usearch/index_dense.hpp:

  • Single-key remove(vector_key_t key) checks if (typed_->is_immutable()) return result.failed("Can't remove from an immutable index");.
  • However, batch remove(keys_iterator_at keys_begin, keys_iterator_at keys_end) and rename(vector_key_t from, vector_key_t to) omitted this check.
  • When an index was opened using view(...), its memory mapping was read-only (is_immutable() == true). Calling rename or batch remove attempted to write into typed_->at(slot).key, triggering a segmentation fault or bus error (SIGBUS) and aborting the process.

Technical Solution

  1. In include/usearch/index_dense.hpp:
    • Added if (typed_->is_immutable()) return result.failed("Can't remove from an immutable index"); to batch remove(keys_iterator_at keys_begin, keys_iterator_at keys_end).
    • Added if (typed_->is_immutable()) return result.failed("Can't rename in an immutable index"); to rename(vector_key_t from, vector_key_t to).
    • Exposed bool is_immutable() const noexcept on index_dense_gt mirroring index_gt::is_immutable().
  2. In cpp/test.cpp:
    • Added automated regression test test_immutable_view that builds and saves an index, maps it via view(...), verifies is_immutable(), and asserts that single remove, batch remove, and rename operations fail gracefully with the expected error, while search operations continue to function normally.

Test Plan

  • Native unit tests: Built test_cpp with GCC 16.1.0 on Windows (MinGW/UCRT64) and executed the suite, confirming test_immutable_view passes cleanly along with all existing unit tests.
  • Local command executed:
    cmake -B build -G Ninja -DUSEARCH_BUILD_TEST_CPP=ON -DCMAKE_CXX_STANDARD_LIBRARIES="-ldbghelp"
    cmake --build build --target test_cpp
    ./build/test_cpp.exe

@ashvardanian

Copy link
Copy Markdown
Member

@Tyagiquamar, thanks for the fix! The 2.x rename and removal paths it guards are gone in 3.0, and #846 tracks how removal returns, with views refusing it outright, so I'm closing this in its favor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: rename and batch remove on a viewed index crash with SIGBUS

2 participants