Skip to content

Validate GatherND indices rank before access - #32349

Merged
Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
msrc/gathernd-runtime-rank-validation
Sep 1, 2026
Merged

Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
msrc/gathernd-runtime-rank-validation

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request introduces a validation check in the GatherND operator to ensure that the indices tensor is not scalar (i.e., has rank greater than 0), and adds a corresponding unit test to verify the new error handling. This prevents invalid inputs from proceeding and improves the robustness of the operator.

Input validation improvements:

  • Added a check in gather_nd.cc to return an error if the indices tensor has zero dimensions, with a clear error message.

Testing enhancements:

  • Added a unit test GatherND_runtime_scalar_indices_error in gather_nd_op_test.cc to verify that passing a scalar indices tensor triggers the expected error.

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

Adds CPU GatherND runtime validation to reject scalar indices safely.

Changes:

  • Validates indices rank before indexing its shape.
  • Adds a CPU regression test for scalar indices.

Reviewed changes

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

File Description
onnxruntime/core/providers/cpu/tensor/gather_nd.cc Adds the rank validation.
onnxruntime/test/providers/cpu/tensor/gather_nd_op_test.cc Tests runtime rejection of scalar indices.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime/core/providers/cpu/tensor/gather_nd.cc
@apsonawane
Akshay Sonawane (apsonawane) merged commit ef965a9 into main Sep 1, 2026
91 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the msrc/gathernd-runtime-rank-validation branch September 1, 2026 16:11
This was referenced Sep 10, 2026
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.

3 participants