Validate ScatterND index depth - #32034
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request strengthens runtime input validation for the CPU ScatterND operator by rejecting indices tensors whose last dimension (index depth) is zero, and adds a unit test to ensure that invalid case is properly rejected.
Changes:
- Add
ValidateShapesguard to requireindices.shape[-1] >= 1, returningINVALID_ARGUMENTotherwise. - Add a unit test that constructs
indiceswith shape{1, 0}and asserts the operator fails with the expected error substring.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/tensor/scatter_nd.h | Adds a shape-validation check to reject zero (or negative) index depth in indices. |
| onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc | Adds a regression test ensuring the new validation triggers for {1, 0} indices. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Major review finding
This rejects For example, Please handle |
Base branch was modified
This pull request improves input validation for the
ScatterNDoperator and adds a corresponding unit test to ensure that invalid input is properly rejected.Input validation:
scatter_nd.hto ensure that the last dimension of theindicestensor is at least 1, returning an error if it is not.Testing:
scatter_nd_op_test.cc(ScatterND_rejects_zero_index_depth) to verify that the operator rejectsindicestensors with a zero-sized last dimension.