3 Commits
Author SHA1 Message Date
Alibek Zhakubayev d492af446e faiss: initialize ids_tab to -1 in Top1BlockResultHandler::begin_multiple (#5249)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5249

Before this change, Top1BlockResultHandler::begin_multiple initialized
dis_tab[i] to C::neutral() but left ids_tab[i] uninitialized for every
query slot. This was inconsistent with two related code paths in the same
class:

1. SingleResultHandler::begin() (the per-query API) explicitly sets
   min_idx = -1 before accumulating results.
2. HeapBlockResultHandler::begin_multiple() calls heap_heapify<C>()
   which sets ids_tab[i*k + j] = -1 for all k result slots.

The inconsistency means that any caller invoking begin_multiple +
end_multiple without an intervening add_results — for example, when
the database is empty and there are no results to report — reads
uninitialized memory from ids_tab instead of the expected -1 sentinel.

Fix: add ids_tab[i] = -1 inside the begin_multiple loop, making the
block API consistent with the single-query API and with the Heap handler.
This is a strictly additive, zero-risk change: in the normal path where
add_results is called and covers all queries, the -1 is overwritten
with the actual winner index before end_multiple returns.

Test: TestTop1BlockResultHandler/BeginMultipleInitializesIds — calls
begin_multiple(0, nq) followed by end_multiple() with no add_results,
then verifies every ids_tab[i] == -1 and dis_tab[i] == C::neutral().

Reviewed By: junjieqi

Differential Revision: D106359898

fbshipit-source-id: f864016703aa98b0c3ff6226968bb61f361a45f7
2026-05-28 13:28:59 -07:00
Michael Norris eff0898a13 Enable linting: lint config changes plus arc lint command (#3966)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3966

This actually enables the linting.

Manual changes:
- tools/arcanist/lint/fbsource-licenselint-config.toml
- tools/arcanist/lint/fbsource-lint-engine.toml

Automated changes:
`arc lint --apply-patches --take LICENSELINT --paths-cmd 'hg files faiss'`

Reviewed By: asadoughi

Differential Revision: D64484165

fbshipit-source-id: 4f2f6e953c94ef6ebfea8a5ae035ccfbea65ed04
2024-10-22 09:46:48 -07:00
Gergely Szilvasy cbff63e3b7 addn_query_subset_with_ids float index bug (#2834)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2834

Index stored in float results in buffer overflow and corrupts search results.

Reviewed By: mdouze

Differential Revision: D45388883

fbshipit-source-id: bee696495b323a13350550d1928d25202539b1f0
2023-04-28 05:14:18 -07:00