Require ImageScaler bias to have one entry per channel - #32002
Merged
Conversation
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>
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 11, 2026 23:31
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 11, 2026 23:32
View session
Contributor
There was a problem hiding this comment.
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
ImageScalernode with an explicitly emptybiasattribute and asserts a validation failure. - Update the CPU kernel to always require
bias_.size() == C(instead of skipping the check whenbias_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.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
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.
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.