Fix out-of-bounds read when a Loop/Scan body input is also an initializer - #32609
Open
Wei Wang (wangw-1991) wants to merge 1 commit into
Open
Wei Wang (wangw-1991) wants to merge 1 commit into
Wei Wang (wangw-1991) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression case still reaches an ORT_ENFORCE that aborts exception-disabled builds instead of returning a clean error.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Prevents out-of-bounds access while mapping Loop/Scan parent inputs to subgraph inputs.
Changes:
- Selects a cardinality-matching subgraph input list and validates bounds.
- Adds a Loop regression test for initializer-backed body inputs.
File summaries
| File | Description |
|---|---|
onnxruntime/core/framework/session_state.cc |
Hardens subgraph input mapping. |
onnxruntime/test/providers/cpu/controlflow/loop_test.cc |
Adds the regression test. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1529
to
+1532
| const auto* subgraph_inputs = &subgraph.GetInputsIncludingInitializers(); | ||
| if (subgraph_inputs->size() != num_parent_inputs) { | ||
| const auto& required_subgraph_inputs = subgraph.GetInputs(); | ||
| if (required_subgraph_inputs.size() != num_parent_inputs) { |
Contributor
Author
|
Tianlei Wu (@tianleiwu) Can you help review this PR or help find suitable reviewers? Thanks. |
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.
Problem
OuterScopeNodeArgLocationAccumulator(session_state.cc) maps a Loop/Scan node's explicit inputs onto the subgraph's inputs usingGraphViewer::GetInputs(), which excludes initializer-backed inputs. When a body declares an input that is also abody initializer,
GetInputs()is shorter than the parent node's input list, so indexingsubgraph_inputs[arg_idx]reads past the end of the vector and dereferences an invalidNodeArgpointer during session initialization. This causes a crash / heap out-of-bounds read (observable under ASan) when loading a malformed model containing such a Loop/Scan.Fix
In the Loop/Scan≥9 branch of
OuterScopeNodeArgLocationAccumulator:GetInputsIncludingInitializers(), fall back toGetInputs()), mirroring the logic already used inGraph::InferAndVerifySubgraphTypes. If neither matches returnINVALID_GRAPHinstead of indexing.Loop.BodyInputAlsoInitializer_RejectedWithoutOutOfBoundsReadtest: a Loop whose body input is also a body initializer is now rejected cleanly instead of crashing.