Skip to content

fix(datacell): validate ID ranges in DenseDuplicateTracker deserialization - #2258

Merged
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:fix/dense-duplicate-tracker-deserialize-bounds-check
Jun 16, 2026
Merged

LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:fix/dense-duplicate-tracker-deserialize-bounds-check

Conversation

@LHT129

@LHT129 LHT129 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2257

Add comprehensive validation for all IDs read from the stream in DenseDuplicateTracker::Deserialize and DeserializeFromLegacyFormat. Without validation, a corrupted or malicious index file could cause heap buffer overflow writes or infinite loops.

Changes

Bounds checks (heap overflow prevention)

  • Validate head_id and each dup_id against size in Deserialize
  • Validate id and each duplicate_id against total_size in DeserializeFromLegacyFormat

Overlap checks (infinite loop prevention)

  • Reject head_id/id that is already part of another group (duplicate_ids_[x] != x)
  • Reject dup_id/duplicate_id that is already assigned to another group

Error message improvements

  • All exceptions use fmt::format to include the offending ID value and the valid bounds
  • Throw VsagException(ErrorType::INVALID_BINARY, ...) for all validation failures

Test Plan

  • All 11 DenseDuplicateTracker tests pass (33 assertions)
  • Tests cover: out-of-range head_id, out-of-range dup_id, overlapping head groups, overlapping member ids
  • Both Deserialize and DeserializeFromLegacyFormat paths tested
  • Existing serialize/deserialize roundtrip tests still pass

Copilot AI review requested due to automatic review settings June 15, 2026 07:46
@LHT129 LHT129 self-assigned this Jun 15, 2026
@pull-request-size pull-request-size Bot added the size/M 30-99 changed lines label Jun 15, 2026
@LHT129 LHT129 added kind/bug Bug fixes, defects, or unexpected behavior 修复程序错误、缺陷或异常行为 version/1.0 1. LazyHGraph & SIMQ 2. Unified search API 3. Streaming serialization 1. 新索引 2. 统一检索接口 3. 流式序列化 labels Jun 15, 2026
@mergify

mergify Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require kind label

Wonderful, this rule succeeded.
  • label~=^kind/

🟢 Require version label

Wonderful, this rule succeeded.
  • label~=^version/

🟢 Require linked issue for feature/bug PRs

Wonderful, this rule succeeded.
  • 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 adds bounds checking during the deserialization of duplicate trackers (for both standard and legacy formats) to prevent out-of-bounds access, along with corresponding unit tests. The reviewer identified a potential denial-of-service vulnerability where corrupted or malicious files could introduce cycles in duplicate groups, leading to infinite loops or out-of-memory crashes. To mitigate this, the reviewer suggested adding checks to ensure that deserialized IDs are not already part of another duplicate group.

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/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds defensive bounds validation during DenseDuplicateTracker deserialization to prevent out-of-range IDs from corrupting memory when reading potentially malformed/corrupted index files.

Changes:

  • Add bounds checks for head_id / dup_id in Deserialize and id / duplicate_id in DeserializeFromLegacyFormat.
  • Throw VsagException(ErrorType::INVALID_BINARY, ...) when encountering out-of-range IDs.
  • Add unit tests covering out-of-range IDs for both current and legacy formats.

Reviewed changes

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

File Description
src/datacell/dense_duplicate_tracker.cpp Adds range checks and throws on invalid IDs during deserialization paths.
src/datacell/dense_duplicate_tracker_test.cpp Adds negative tests asserting invalid IDs are rejected via exceptions.

Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
@LHT129
LHT129 force-pushed the fix/dense-duplicate-tracker-deserialize-bounds-check branch from 54d1cb6 to 91dbce6 Compare June 15, 2026 08:18
@pull-request-size pull-request-size Bot added size/L 100-499 changed lines and removed size/M 30-99 changed lines labels Jun 15, 2026
Copilot AI review requested due to automatic review settings June 15, 2026 08:43
@LHT129
LHT129 force-pushed the fix/dense-duplicate-tracker-deserialize-bounds-check branch from 91dbce6 to 301bbea Compare June 15, 2026 08:43

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

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

Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker.cpp
Comment thread src/datacell/dense_duplicate_tracker_test.cpp
Comment thread src/datacell/dense_duplicate_tracker_test.cpp
Comment thread src/datacell/dense_duplicate_tracker_test.cpp
Comment thread src/datacell/dense_duplicate_tracker_test.cpp
…ation

Add bounds checks for head_id, dup_id, and all IDs read from the stream
in both Deserialize and DeserializeFromLegacyFormat. Without validation,
a corrupted or malicious index file could provide IDs exceeding the
vector size, causing heap buffer overflow writes via duplicate_ids_[id].

Throw VsagException with INVALID_BINARY when any ID is out of range.

Signed-off-by: tianlan.lht <tianlan.lht@antgroup.com>
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@LHT129
LHT129 force-pushed the fix/dense-duplicate-tracker-deserialize-bounds-check branch from 301bbea to 884e4c5 Compare June 15, 2026 09:27

@wxyucs wxyucs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@LHT129
LHT129 merged commit 8cae7cb into antgroup:main Jun 16, 2026
19 of 20 checks passed
@LHT129
LHT129 deleted the fix/dense-duplicate-tracker-deserialize-bounds-check branch June 16, 2026 04:33
Sia-Sheerland pushed a commit to Sia-Sheerland/vsag that referenced this pull request Jun 26, 2026
…ation (antgroup#2258)

fix(hgraph): add bounds checks on IDs during label table deserialization

Without validation, a corrupted or malicious index file could provide
head_id, dup_id, or stream-read IDs exceeding the vector size, causing
heap buffer overflow writes via duplicate_ids_[id].

Add bounds checks for all such IDs in both Deserialize and
DeserializeFromLegacyFormat; throw VsagException(INVALID_BINARY) on
any out-of-range value.

Assisted-by: OpenCode:claude-opus-4.7
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Signed-off-by: Sia Sheerland <x1075956441x@163.com>

Signed-off-by: Sia Sheerland <x1075956441x@163.com>
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/L 100-499 changed lines version/1.0 1. LazyHGraph & SIMQ 2. Unified search API 3. Streaming serialization 1. 新索引 2. 统一检索接口 3. 流式序列化

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug](datacell): DenseDuplicateTracker Deserialize heap buffer overflow due to unvalidated IDs

3 participants