Skip to content

fix(iter_filter): add bound check for iter filter context#1608

Merged
inabao merged 2 commits into0.16from
cherry-pick-e7b7a01-fix
Feb 28, 2026
Merged

fix(iter_filter): add bound check for iter filter context#1608
inabao merged 2 commits into0.16from
cherry-pick-e7b7a01-fix

Conversation

@inabao
Copy link
Copy Markdown
Collaborator

@inabao inabao commented Feb 27, 2026

cp #1588 to 0.16
link #1579 #1580

Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
@inabao inabao self-assigned this Feb 27, 2026
@inabao inabao added kind/bug Something isn't working version/0.16 labels Feb 27, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses several issues related to the IteratorFilterContext and graph search algorithms. It introduces robust error handling for empty graphs, prevents potential out-of-bounds memory access within the iterator filter, and refines the search logic in HNSW and basic searcher implementations for improved correctness and efficiency.

Highlights

  • Empty Graph Handling: Introduced a check in HGraph::KnnSearch to handle cases where the graph has zero elements, returning an empty dataset immediately to prevent errors during IteratorFilterContext initialization.
  • Iterator Filter Bound Checks: Implemented boundary checks within IteratorFilterContext::SetPoint and IteratorFilterContext::CheckPoint to prevent out-of-bounds access when inner_id exceeds max_size_.
  • Search Logic Refinement: Adjusted the order of operations in HierarchicalNSW::searchBaseLayerST and BasicSearcher::search_impl to ensure visited_array or vl is marked before calling iter_ctx->CheckPoint, streamlining the search logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/algorithm/hgraph.cpp
    • Added a check for cur_count == 0 to return an empty dataset early in KnnSearch.
  • src/algorithm/hnswlib/hnswalg.cpp
    • Reordered visited_array marking to occur before iter_ctx->CheckPoint call in searchBaseLayerST.
  • src/impl/basic_searcher.cpp
    • Reordered vl marking to occur before iter_ctx->CheckPoint call in search_impl.
  • src/index/iterator_filter.cpp
    • Added inner_id >= max_size_ bound check in SetPoint.
    • Added inner_id < max_size_ bound check in CheckPoint.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify mergify bot added the module/index label Feb 27, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a bounds check issue in the iterator filter context. The changes in src/index/iterator_filter.cpp correctly add bounds checks to SetPoint and CheckPoint, preventing potential out-of-bounds memory access. The addition of an empty graph check in src/algorithm/hgraph.cpp also improves robustness.

However, the modifications in src/algorithm/hnswlib/hnswalg.cpp and src/impl/basic_searcher.cpp appear to be problematic. They remove a necessary de-duplication check for candidates, which could lead to incorrect search results and performance issues. Furthermore, the changes do not fully resolve the underlying out-of-bounds access vulnerability. I have provided suggestions to correctly fix the potential crash while maintaining the de-duplication logic.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (70.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

@@            Coverage Diff             @@
##             0.16    #1608      +/-   ##
==========================================
+ Coverage   92.21%   92.30%   +0.08%     
==========================================
  Files         295      295              
  Lines       15677    15688      +11     
==========================================
+ Hits        14457    14481      +24     
+ Misses       1220     1207      -13     
Flag Coverage Δ
cpp 92.30% <70.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 92.62% <ø> (ø)
datacell 92.73% <ø> (+0.83%) ⬆️
index 91.22% <78.57%> (-0.28%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31735f3...caa8836. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@inabao inabao merged commit d4fec06 into 0.16 Feb 28, 2026
22 of 23 checks passed
@inabao inabao deleted the cherry-pick-e7b7a01-fix branch February 28, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants