Skip to content

Fix out-of-bounds issue#1077

Open
apsonawane wants to merge 2 commits into
mainfrom
asonawane/segment
Open

Fix out-of-bounds issue#1077
apsonawane wants to merge 2 commits into
mainfrom
asonawane/segment

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request adds input validation to the segment_sum operator to ensure that segment_ids does not contain negative values and that all values are within the valid range. It also introduces a test to verify that negative segment_ids are correctly rejected.

Input validation improvements:

  • Added checks in segment_sum (in operators/math/segment_sum.cc) to return an error if any value in segment_ids is negative, including the first and last elements.
  • Added a check to ensure all segment_ids values are within the range [0, last_seg], returning an error if out of bounds.

Testing:

  • Added a unit test test_segment_sum_cc_negative_segment_ids in test/test_math_ops.py to verify that the operator raises an exception when segment_ids contains negative values.

Copilot AI review requested due to automatic review settings June 10, 2026 19:59
@apsonawane apsonawane requested a review from a team as a code owner June 10, 2026 19:59

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 pull request strengthens the SegmentSum custom operator by adding runtime input validation for segment_ids to prevent invalid indexing behavior, and adds a regression test to ensure negative segment_ids are rejected.

Changes:

  • Add validation in segment_sum to reject negative segment_ids and values outside the computed valid range.
  • Add a Python unit test that asserts an error is raised when segment_ids contains a negative value.

Reviewed changes

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

File Description
operators/math/segment_sum.cc Adds segment_ids validation (negative / range) before using values for output indexing.
test/test_math_ops.py Adds a unit test ensuring negative segment_ids are rejected by the C++ operator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread operators/math/segment_sum.cc Outdated
Comment thread operators/math/segment_sum.cc
@apsonawane apsonawane enabled auto-merge (squash) June 11, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants