Validate per-element split sizes on the input-tensor path to prevent OOB read - #29461
Merged
Akshay Sonawane (apsonawane) merged 2 commits intoAug 20, 2026
Merged
Conversation
…OOB read The Split operator's split-as-attribute path validates that each split size is non-negative (in the constructor), but the split-as-input-tensor path skips that check and only validates the aggregate (sum == axis dim, count == num_outputs). A negative split size like [6, -2] on a dim of size 4 passes the aggregate check (sum = 4) and causes the kernel to read 6 rows from a 4-row input buffer before the second output's negative-size allocation throws. Add per-element >= 0 validation in PrepareForCompute (CPU/WebGPU/shared- provider) and PrepareForComputeLocal (CUDA) before the aggregate checks. Add a unit test that supplies negative split sizes via an input tensor and expects failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 17, 2026 18:11
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds per-element Split validation to prevent out-of-bounds reads from negative input-tensor split sizes.
Changes:
- Validates split sizes in shared CPU and CUDA preparation paths.
- Adds a regression test for
[6, -2].
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
onnxruntime/core/providers/cpu/tensor/split.h |
Adds shared split-size validation. |
onnxruntime/core/providers/cuda/tensor/split.cc |
Mirrors validation for CUDA. |
onnxruntime/test/providers/cpu/tensor/split_op_test.cc |
Tests negative split rejection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Resolve the Split test conflict with main and validate split sizes cumulatively against the remaining axis extent to avoid signed overflow bypasses. Add a regression test for [6, INT64_MAX, INT64_MAX]. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d814472-441f-441d-bd46-931956efc1cd
Akshay Sonawane (apsonawane)
approved these changes
Aug 20, 2026
Akshay Sonawane (apsonawane)
deleted the
chilo-ms/split-negative-input-validation
branch
August 20, 2026 19:06
This was referenced Sep 10, 2026
Open
This was referenced Sep 14, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Split operator's split-as-attribute path validates that each split size is non-negative (in the constructor), but the split-as-input-tensor path skips that check and only validates the aggregate (sum == axis dim, count == num_outputs). A crafted negative split size like [6, -2] on an axis of size 4 passes the aggregate check ( 6 + (-2) = 4 ) and causes the kernel to copy 6 rows from a 4-row input — an out-of-bounds read.
Changes:
• split.h ( PrepareForCompute ): Per-element >= 0 validation. Covers CPU, WebGPU, shared-provider paths.
• cuda/tensor/split.cc ( PrepareForComputeLocal ): Same fix in the CUDA copy.
• split_op_test.cc : NegativeSplitSizeInputTensor test with split = [6, -2] expecting failure.
Motivation and Context