Harden shape inference for contrib ops - #32607
Open
shiyi (shiyi9801) wants to merge 3 commits into
Open
shiyi (shiyi9801) wants to merge 3 commits into
shiyi (shiyi9801) wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
Dwayne Robinson (@fdwr) PTAL, thanks! |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Invalid ndim values remain accepted when input shape metadata is absent, and the new guards lack regression tests.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Hardens contrib-op shape inference against malformed model metadata.
Changes:
- Validates CausalConvWithState ranks and
ndim. - Guards GatedDeltaNet width arithmetic against overflow.
- Rejects empty attention sequence-length initializers.
File summaries
| File | Description |
|---|---|
onnxruntime/core/graph/contrib_ops/bert_defs.cc |
Adds shape, attribute, initializer, and overflow validation. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+2903
to
+2907
| if (ndim < 1 || ndim > 3) { | ||
| fail_shape_inference("CausalConvWithState: ndim must be 1, 2, or 3, got ", ndim); | ||
| } | ||
| if (weight_shape.dim_size() < 2) { | ||
| fail_shape_inference("CausalConvWithState: weight must have rank >= 2"); | ||
| // weight is always channels-first: (channels, 1, k_1, ..., k_ndim), rank == ndim + 2. | ||
| if (weight_shape.dim_size() != ndim + 2) { |
Comment on lines
+3580
to
+3583
| constexpr int64_t max_dimension = std::numeric_limits<int64_t>::max(); | ||
| if (num_heads_k > max_dimension / head_size_qk || | ||
| num_heads_v > max_dimension / head_size_v) { | ||
| fail_shape_inference("GatedDeltaNet: state_update width overflows int64"); |
46 tasks
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.
Summary
Strengthens attribute/input validation in three contrib-op shape-inference functions in bert_defs.cc so malformed or malicious models are rejected at
Graph::Resolveinstead of triggering out-of-bounds reads or signed-integer overflow during shape inference.Changes
CausalConvWithState: validate the ndim attribute is in [1, 3] and cross-check tensor ranks against it (weight == ndim+2, channels-first input == ndim+2, channels-last input >= 3) before the spatial-dim loop indexes input.dim(2+i). Previously only a rank >= 2 guard existed, so ndim=2/3 with a low-rank input read past the shape's dimensions.GatedDeltaNet: require the head counts/sizes to be positive and add step-by-step overflow guards before computing the state_update capsule width, preventing signed int64 overflow (UB) in state_update_capacity * (num_heads_v + num_heads_khead_size_qk + num_heads_vhead_size_v).GroupQueryAttention/SparseAttention: check the parsedtotal_sequence_lengthinitializer is non-empty before indexing data[0].