Skip to content

Validate per-element split sizes on the input-tensor path to prevent OOB read - #29461

Merged
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
chilo-ms/split-negative-input-validation
Aug 20, 2026
Merged

Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
chilo-ms/split-negative-input-validation

Conversation

@chilo-ms

Copy link
Copy Markdown
Contributor

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

…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 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 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.

Comment thread onnxruntime/core/providers/cuda/tensor/split.cc
Comment thread onnxruntime/core/providers/cpu/tensor/split.h
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
@apsonawane
Akshay Sonawane (apsonawane) merged commit abc74dc into main Aug 20, 2026
91 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the chilo-ms/split-negative-input-validation branch August 20, 2026 19:06
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