Skip to content

fix(datacell, odescent): fix multiple out-of-bounds array accesses#2364

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:P2重要-2026-06-16-修复-多处数组越界访问-graphdatacell-odescent-sparsetermdatacell

Hidden character warning

The head ref may contain hidden characters: "P2\u91cd\u8981-2026-06-16-\u4fee\u590d-\u591a\u5904\u6570\u7ec4\u8d8a\u754c\u8bbf\u95ee-graphdatacell-odescent-sparsetermdatacell"
Open

fix(datacell, odescent): fix multiple out-of-bounds array accesses#2364
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:P2重要-2026-06-16-修复-多处数组越界访问-graphdatacell-odescent-sparsetermdatacell

Conversation

@LHT129

@LHT129 LHT129 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix three out-of-bounds array/vector accesses in src/:

  • src/datacell/graph_datacell.h: DeleteNeighborsById / RecoverDeleteNeighborsById use id <= max_capacity_, allowing id == max_capacity_ which is one past the end of node_versions_.
  • src/impl/odescent/odescent_graph_builder.cpp: ODescent::repair_no_in_edge reads link[need_replace_loc] and graph_[...].neighbors[replace_pos[...]] without verifying the post-update_neighbors actual container sizes.
  • src/datacell/sparse_term_datacell.cpp: SparseTermDataCell::DocPrune accumulates sorted_base[i].second until temp_mass >= part_mass; floating-point error near doc_retain_ratio_ = 1.0 can push pruned_doc_len past the end.

All changes are minimal boundary-condition fixes and do not affect normal-path behavior.

Fixes #2363

Changes

src/datacell/graph_datacell.h                | 4 ++--
src/datacell/sparse_term_datacell.cpp        | 2 +-
src/impl/odescent/odescent_graph_builder.cpp | 6 +++++-
3 files changed, 8 insertions(+), 4 deletions(-)

Verification

  • make fmt passes.
  • Source files end with newlines.
  • One signed-off-by commit on top of github/main.

(Build/Test steps skipped on operator instruction due to local environment limitations; reviewers are asked to run CI.)

Copilot AI review requested due to automatic review settings June 29, 2026 07:03
@LHT129 LHT129 added kind/bug Bug fixes, defects, or unexpected behavior 修复程序错误、缺陷或异常行为 version/1.0 labels Jun 29, 2026
@LHT129 LHT129 self-assigned this Jun 29, 2026
@mergify

mergify Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 3 merge protections satisfied — ready to merge.

Show 3 satisfied protections

🟢 Require kind label

  • label~=^kind/

🟢 Require version label

  • label~=^version/

🟢 Require linked issue for feature/bug PRs

  • body~=(?im)(?:^|[\s\-\*])(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*:?\s+(?:#\d+|[\w.\-]+/[\w.\-]+#\d+|https?://github\.com/[\w.\-]+/[\w.\-]+/issues/\d+)

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

Copy link
Copy Markdown
Contributor

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 introduces critical bounds checks to prevent potential out-of-bounds accesses in GraphDataCell, SparseTermDataCell, and ODescent. In odescent_graph_builder.cpp, the proposed check for replace_pos can be improved; instead of skipping the repair entirely when the index is out of bounds, capping the index to the maximum valid neighbor list size allows the repair logic to continue functioning correctly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/impl/odescent/odescent_graph_builder.cpp
@LHT129 LHT129 marked this pull request as ready for review June 29, 2026 07:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes three boundary-condition out-of-bounds array/vector access bugs in the C++ src/ implementation (GraphDataCell delete/recover, ODescent graph repair, and SparseTermDataCell doc pruning), aligning behavior with the intended container bounds and eliminating undefined behavior paths described in issue #2363.

Changes:

  • Fix an off-by-one capacity check in GraphDataCell::{DeleteNeighborsById, RecoverDeleteNeighborsById} (<=<).
  • Add post-update_neighbors() size guards in ODescent::repair_no_in_edge() to avoid indexing beyond actual neighbor list lengths.
  • Bound SparseTermDataCell::DocPrune()’s accumulation loop to prevent walking past sorted_base.size().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/datacell/graph_datacell.h Tightens ID bound checks to prevent OOB access to node_versions_ on the capacity boundary.
src/impl/odescent/odescent_graph_builder.cpp Adds container-size-based guards in repair_no_in_edge() to prevent OOB reads after neighbor list compaction.
src/datacell/sparse_term_datacell.cpp Adds loop bound in DocPrune() so pruning cannot read past the end of sorted_base.

Comment thread src/datacell/graph_datacell.h
Comment thread src/impl/odescent/odescent_graph_builder.cpp
Comment thread src/datacell/sparse_term_datacell.cpp
Three boundary-condition fixes in src/: GraphDataCell uses `<=` where `<`
is required to keep the index inside `node_versions_`; ODescent
`repair_no_in_edge` does not check the post-`update_neighbors` linker
sizes when traversing and indexing into `graph_[...].neighbors`;
SparseTermDataCell `DocPrune` accumulates mass without bounding
`pruned_doc_len` against the container size, which can read past the
end on near-1.0 ratios due to floating-point error.

All three changes only add or tighten boundary checks and do not
affect behavior on normal paths.

Signed-off-by: opencode <opencode@anthropic.com>
Co-authored-by: opencode <opencode@anthropic.com>
@LHT129 LHT129 force-pushed the P2重要-2026-06-16-修复-多处数组越界访问-graphdatacell-odescent-sparsetermdatacell branch from b4bf1d8 to 1335cad Compare June 29, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bug fixes, defects, or unexpected behavior 修复程序错误、缺陷或异常行为 size/S version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Multiple out-of-bounds array accesses in src/ (GraphDataCell, ODescent, SparseTermDataCell)

2 participants