Skip to content

Require ImageScaler bias to have one entry per channel - #32002

Merged
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/image-scaler-bias-size
Aug 13, 2026
Merged

Require ImageScaler bias to have one entry per channel#32002
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/image-scaler-bias-size

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

The bias size check was skipped whenever bias_ was empty, but the compute loop unconditionally reads one bias entry per channel. A model carrying a present-but-empty bias attribute therefore passed validation and then indexed an empty vector. GetAttrs returns OK for a present attribute regardless of element count, so the empty case was reachable from a model file.

An empty bias is not a usable state in either kernel: the constructor already fails outright when the attribute is absent, so requiring the size to equal the channel count keeps the existing contract and closes the gap. The CUDA kernel had the same check and the same per-channel read, so both are updated.

The bias size check was skipped whenever bias_ was empty, but the compute loop unconditionally reads one bias entry per channel. A model carrying a present-but-empty bias attribute therefore passed validation and then indexed an empty vector. GetAttrs returns OK for a present attribute regardless of element count, so the empty case was reachable from a model file.

An empty bias is not a usable state in either kernel: the constructor already fails outright when the attribute is absent, so requiring the size to equal the channel count keeps the existing contract and closes the gap. The CUDA kernel had the same check and the same per-channel read, so both are updated.

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

This PR tightens runtime validation for the ImageScaler contrib kernels to ensure the bias attribute has exactly one value per input channel, preventing an out-of-bounds read when a model provides a present-but-empty bias list.

Changes:

  • Add a regression test that constructs an ImageScaler node with an explicitly empty bias attribute and asserts a validation failure.
  • Update the CPU kernel to always require bias_.size() == C (instead of skipping the check when bias_ is empty).
  • Update the CUDA kernel with the same always-on size check to match the per-channel bias indexing behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
onnxruntime/test/contrib_ops/tensor_op_test.cc Adds a test covering the present-but-empty bias attribute case (expects failure).
onnxruntime/contrib_ops/cuda/tensor/image_scaler.cc Enforces bias length equals channel count in CUDA kernel ComputeInternal.
onnxruntime/contrib_ops/cpu/image_scaler.h Enforces bias length equals channel count in CPU kernel Compute.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@apsonawane
Akshay Sonawane (apsonawane) merged commit 8803b00 into main Aug 13, 2026
89 of 90 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/image-scaler-bias-size branch August 13, 2026 17:53
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