Repository navigation
fix(dense): reject rename and batch remove on immutable viewed index - #841
Closed
Tyagiquamar wants to merge 1 commit into
Closed
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
Signed-off-by: Tyagiquamar <[email protected]>
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. |
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 #835 by preventing
renameand batchremoveoperations 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:remove(vector_key_t key)checksif (typed_->is_immutable()) return result.failed("Can't remove from an immutable index");.remove(keys_iterator_at keys_begin, keys_iterator_at keys_end)andrename(vector_key_t from, vector_key_t to)omitted this check.view(...), its memory mapping was read-only (is_immutable() == true). Callingrenameor batchremoveattempted to write intotyped_->at(slot).key, triggering a segmentation fault or bus error (SIGBUS) and aborting the process.Technical Solution
include/usearch/index_dense.hpp:if (typed_->is_immutable()) return result.failed("Can't remove from an immutable index");to batchremove(keys_iterator_at keys_begin, keys_iterator_at keys_end).if (typed_->is_immutable()) return result.failed("Can't rename in an immutable index");torename(vector_key_t from, vector_key_t to).bool is_immutable() const noexceptonindex_dense_gtmirroringindex_gt::is_immutable().cpp/test.cpp:test_immutable_viewthat builds and saves an index, maps it viaview(...), verifiesis_immutable(), and asserts that singleremove, batchremove, andrenameoperations fail gracefully with the expected error, while search operations continue to function normally.Test Plan
test_cppwith GCC 16.1.0 on Windows (MinGW/UCRT64) and executed the suite, confirmingtest_immutable_viewpasses cleanly along with all existing unit tests.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