Skip to content

fix: guard extra_info pointer arithmetic against nullptr in BruteForce::Add#2168

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:claude-opus/fix-bruteforce-extra-info-nullptr-ub
Open

fix: guard extra_info pointer arithmetic against nullptr in BruteForce::Add#2168
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:claude-opus/fix-bruteforce-extra-info-nullptr-ub

Conversation

@LHT129

@LHT129 LHT129 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Fixes: #2167

Summary

When extra_info is nullptr (the common case when no extra info is provided), BruteForce::Add performs nullptr + j * extra_info_size, which is undefined behavior in C++.

This PR adds a null check before the pointer arithmetic, consistent with the pattern already used in warp.cpp:189.

Changes

  • src/algorithm/bruteforce/bruteforce.cpp: Extract ei_ptr with null check before passing to GeneralEnqueue / add_func

Test plan

  • Existing bruteforce functional tests pass (28 test cases, 715363 assertions)
  • Release build succeeds

…e::Add

When extra_info is nullptr, performing pointer arithmetic (nullptr + offset)
is undefined behavior in C++. Add a null check before the arithmetic,
consistent with the pattern already used in warp.cpp.

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Co-authored-by: opencode <opencode@anthropic.com>
Copilot AI review requested due to automatic review settings June 8, 2026 11:58
@LHT129 LHT129 self-assigned this Jun 8, 2026
@mergify

mergify Bot commented Jun 8, 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 updates the brute-force algorithm implementation to safely handle cases where extra_info is null. It introduces a helper pointer ei_ptr to prevent undefined behavior from pointer arithmetic on a null pointer. There are no review comments, so I have no additional feedback to provide.

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.

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 undefined behavior in BruteForce::Add by preventing pointer arithmetic on a null extra_info pointer, aligning the implementation with the existing null-guard pattern used elsewhere (e.g., warp.cpp).

Changes:

  • Add a per-element ei_ptr computed via extra_info == nullptr ? nullptr : extra_info + j * extra_info_size.
  • Use ei_ptr for both the threaded (GeneralEnqueue) and non-threaded (add_func) add paths.

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.

BruteForce::Add performs undefined pointer arithmetic on nullptr extra_info

2 participants