Skip to content

fix(add/update): bound-check contexts_ before indexing into it - #757

Merged
ashvardanian merged 1 commit into
unum-cloud:main-devfrom
desertfury:fix/fuzz-add-after-reset-segv
May 24, 2026
Merged

ashvardanian merged 1 commit into
unum-cloud:main-devfrom
desertfury:fix/fuzz-add-after-reset-segv

Conversation

@desertfury

Copy link
Copy Markdown
Contributor

After a failed load_from_stream (or any path that ends in index_gt::reset()), contexts_ is empty but is_immutable() is still false. The very next add() then read contexts_[0] out of a zero-size buffer — UBSan flagged the null reference and ASAN SEGV'd inside the clear() chain that followed.

Adds an explicit contexts_.size() <= config.thread guard at the top of both add() and update(), returning the same "Reserve capacity ahead of insertions" error the existing capacity-check uses elsewhere. search() already handled this case via its own null-data check.

@desertfury
desertfury force-pushed the fix/fuzz-add-after-reset-segv branch 2 times, most recently from c6b8fec to e5cfd10 Compare May 24, 2026 10:28
After a failed load resets the underlying graph, the dense wrapper can remain mutable while its per-thread context buffers are empty. The next operation could then acquire no worker thread and index into empty per-thread storage.

Represent failed automatic thread acquisition explicitly and fail dense operations before touching cast buffers or typed contexts. The lower-level graph insertion paths share a single context lookup helper instead of open-coded bounds checks.

Co-authored-by: Mikhail Chichvarin <[email protected]>

Co-authored-by: Mikhail Chichvarin <[email protected]>

Co-authored-by: Ash Vardanian <[email protected]>
@ashvardanian
ashvardanian force-pushed the fix/fuzz-add-after-reset-segv branch from e5cfd10 to 1e52d0a Compare May 24, 2026 12:04
@ashvardanian
ashvardanian changed the base branch from main to main-dev May 24, 2026 12:51
@ashvardanian
ashvardanian merged commit b8d3403 into unum-cloud:main-dev May 24, 2026
ashvardanian pushed a commit that referenced this pull request May 24, 2026
### Patch

- Fix: Refuse operations without reserved thread contexts (#757) (b8d3403)
- Fix: Checked arithmetic for allocation sizes (#763) (89da7c5)
- Fix: Preserve hash lookup capacity across thread reserves (#765) (3cf843b)
- Fix: Guard quantized casts against zero-magnitude inputs (#758) (0c903f4)
- Fix: Refuse missing metrics in C change-metric API (#760) (490c1b2)
- Fix: Short-circuit self-renames (#761) (830f31a)
- Fix: Keep `vectors_lookup_` capacity after `clear()` #759 (9d77be5)
- Improve: Serialize concurrent same-`Index` Python access with a mutex (47528b5)
- Improve: Test GIL-release contract and progress-callback path (a598493)
- Improve: Release Python GIL during long index operations (d8be67d)
- Fix: Restore `ring_gt::try_push` return value (18c44ee)
- Fix: Stop JavaScript `Remove` loop after exception throw (f3e1052)
- Fix: Stop `usearch_init` on `make` failure (2aa0070)
- Fix: Stop C-ABI metadata readers on failure (34889ee)
- Fix: Report OOM from C-ABI thread-limit changers (ad24056)
- Fix: Bounded probe in `equal_iterator_gt::operator++` (b779c47)
- Fix: Resize cast buffer in `change_metric` for new bytes-per-vector (d544745)
- Fix: Eager-reserve thread contexts in `index_dense_gt::make` (#755) (b296566)
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.

3 participants