Skip to content

Validate tensor slicing, sparse CSR shapes, and opset versions - #33632

Open
m00dy (professor-moody) wants to merge 1 commit into
microsoft:mainfrom
professor-moody:fix-tensor-slicer-sparse-csr-and-opset-bounds
Open

m00dy (professor-moody) wants to merge 1 commit into
microsoft:mainfrom
professor-moody:fix-tensor-slicer-sparse-csr-and-opset-bounds

Conversation

@professor-moody

Copy link
Copy Markdown

Summary

Reject invalid tensor-slicer indices, overflow-prone sparse CSR shape metadata, and ONNX opset versions that cannot be represented by the runtime. Also propagate model-loading failures instead of continuing after a failed status.

Changes

  • Validate the slice dimension and dimension-zero offset before creating tensor views.
  • Express the CSR row invariant without overflowing rows + 1.
  • Validate imported opset versions before narrowing them to int.
  • Return the model-loading status immediately on failure.
  • Preserve transformer coverage by removing a duplicate zero-version import from one legacy fixture in memory before that test loads the model.
  • Add valid and invalid slicer tests, a sparse CSR overflow-boundary test, and invalid opset version tests.

Testing

  • Built the full onnxruntime_test_all target in Release mode on Linux.
  • Test-only baseline: 2,504 passed, 2 added regression tests failed, and 26 existing environment-dependent tests skipped.
  • Patched full suite: 2,506 passed and the same 26 existing tests skipped.
  • Pre-run and post-run hashes match within each execution, and the red and green executable hashes differ.

## Summary

Reject invalid tensor-slicer indices, overflow-prone sparse CSR shape metadata, and ONNX opset versions that cannot be represented by the runtime. Also propagate model-loading failures instead of continuing after a failed status.

## Changes

- Validate the slice dimension and dimension-zero offset before creating tensor views.
- Express the CSR row invariant without overflowing `rows + 1`.
- Validate imported opset versions before narrowing them to `int`.
- Return the model-loading status immediately on failure.
- Preserve transformer coverage by removing a duplicate zero-version import from one legacy fixture in memory before that test loads the model.
- Add valid and invalid slicer tests, a sparse CSR overflow-boundary test, and invalid opset version tests.

## Testing

- Built the full onnxruntime_test_all target in Release mode on Linux.
- Test-only baseline: 2,504 passed, 2 added regression tests failed, and 26 existing environment-dependent tests skipped.
- Patched full suite: 2,506 passed and the same 26 existing tests skipped.
- Pre-run and post-run hashes match within each execution, and the red and green executable hashes differ.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 23:53
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

The focused validation changes have regression coverage, and no actionable issues were identified across the seven reviewed files.

No open issues 🎉

What changed in this PR

This PR strengthens ONNX Runtime’s input validation for tensor slicing, sparse CSR conversion, and model loading.

Changes:

  • Reject invalid slice indices and opset versions before indexing or narrowing.
  • Avoid overflow in CSR row validation and propagate model-loading failures.
  • Add regression tests and normalize a legacy fixture’s invalid opset import in memory.
File Description
onnxruntime/​test/​ir/​onnx_model_test.cc Tests rejection of invalid opset versions.
onnxruntime/​test/​framework/​tensor_test.cc Adds valid and invalid tensor-slicer cases.
onnxruntime/​test/​framework/​sparse_kernels_test.cc Tests the CSR row-count overflow boundary.
onnxruntime/​test/​framework/​insert_cast_transformer_test.cc Removes an invalid duplicate import before loading the fixture.
onnxruntime/​core/​graph/​model.cc Validates opset versions and returns loading failures.
onnxruntime/​core/​framework/​sparse_utils.cc Makes the CSR row invariant overflow-safe.
onnxruntime/​core/​framework/​ort_value_tensor_slicer.cc Validates slice dimensions and dimension-zero offsets.

Review effort: Balanced

This branch has not been deployed

No deployments
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