Repository navigation
Bound file-controlled sizes in view(): levels region and dense vectors span (OOB read on crafted index) - #776
Merged
ashvardanian merged 2 commits intoAug 22, 2026
Merged
ashvardanian merged 2 commits into
ashvardanian merged 2 commits into
Conversation
…s span index_gt::view walked the memory-mapped levels[] array (sized from the file's header.size) before the only file-size check, and index_dense::view formed a matrix_rows*matrix_cols span into the mapping with no bound plus an unsigned-underflow header guard. A crafted .usearch index over-read the mapping. Bound the levels region before the offset-precompute loop, bound the vectors span with a checked multiply, and make the header guard underflow-safe. Validated with AddressSanitizer (crafted rejected cleanly, valid indexes still load).
Contributor
Author
|
Small correction to the Impact section of this PR: I named a Python entry point that does not exist. I wrote The entry points that actually memory-map, and therefore reach
Nothing else changes. The two sinks and the fix are unaffected. |
`view` takes `offset` publicly, so every `file.size() - offset` in it underflows into a huge span for an offset past the end rather than failing. Guard it once on entry, which makes the added disjunct in the header check redundant. Add a regression test that truncates a saved index and expects `view` to refuse it, in place and at an offset past the end. Without the bounds checks it segfaults in the `memcpy` that reads the dense header.
ashvardanian
pushed a commit
that referenced
this pull request
Aug 22, 2026
xet7
pushed a commit
to xet7/usearch
that referenced
this pull request
Nov 12, 2026
The 2.x line released v2.25.2 through v2.26.6 after 3.0 branched at v2.25.1, and its public main ends at 33d3ab6. Installs place headers under GNUInstallDirs' include directory (14f9807, unum-cloud#800), the README lists the integrations 2.x added (0fd2f32, unum-cloud#795), and CONTRIBUTING states the commit conventions in place of stale links (06ad060, unum-cloud#748). Its correctness fixes already hold on 3.0's code: - Keys move with their entries when `compact` permutes slots (0a4baa6, unum-cloud#795), and the insert-only key table never rehashes (1633e25, unum-cloud#822; 9d77be5, unum-cloud#759) - File loads bound every column slice from the header (9c25176, unum-cloud#824; 64d10d8, unum-cloud#776), and allocation sizes are checked (89da7c5, unum-cloud#763) - JavaScript keys are range-checked (b65a420, unum-cloud#812), Go filters ride `cgo.Handle`s (ad77fe7, unum-cloud#825), `splitmix64_t` survives `windows.h` (0f1c5f2, unum-cloud#806), and integer key hashes mix with SplitMix64 (9fc3500, unum-cloud#773) - C install targets and relocatable pkg-config (4160e47, 679e190, unum-cloud#800), the GIL released in long calls (d8be67d, unum-cloud#764), and graph cursors in C and Rust (55c43f7, unum-cloud#748) Thread-context reserves, tombstones, renames, `change_metric`, OpenMP metrics and hand-written BF16 casts are absent from 3.0, so their fixes have nothing to land on. The Rust `compact()` binding (749d03b, unum-cloud#771) waits for all bindings to wrap `usearch_dense_compact`. The README's performance lead now quotes the SIFT 100M rows at 99% recall on a B300 and on 192 Graviton5 cores beside FAISS HNSW, and the verification notes link ForkUnion's `main`. The sibling pins move to the libraries' own merges with their released lines, so this line builds against them. Co-Authored-By: Jonathan Ringer <[email protected]>
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
index_gt::view(andindex_dense::view) read file-controlled sizes and dereference the memory mapping before bounding them, so a crafted.usearchindex over-reads the mapping. Two sinks:Base
view()levels region (index.hpp):viewsizes a memory-mappedlevels[]array from the file'sheader.sizeand walks it in the offset-precompute loop before theif (file.size() < total_bytes)check runs. A crafted header declaring more nodes than the file contains readslevels[]past the mapping. Fix: reject when the file does not extend tofirst_offset(the end of the levels array) before the loop.Dense
view()vectors span (index_dense.hpp):vectors_buffer = {file.data() + offset, matrix_rows * matrix_cols}forms a span with no file-size check (and the product can overflowsize_t), and the followingif (file.size() - offset < sizeof(buffer))guard is an unsigned subtraction that underflows onceoffsetpassesfile.size(). Fix: bound the span with a checked multiply and make the header guard underflow-safe.Impact
Memory-mapping a crafted or untrusted
.usearchindex viaIndex.view/Index.load(..., view=True)yields an out-of-bounds read (crash / adjacent-memory disclosure). CWE-125.Validation
AddressSanitizer, control vs crafted, driving the real
view()over a buffer-backed mapping: a well-formed index loads cleanly; a crafted one (header.sizelarger than the file / oversized matrix dims) is now rejected with a clear error and no OOB. Found with a structure-aware model/index parser fuzzer.