Validate in-memory initializer references - #32042
Merged
Akshay Sonawane (apsonawane) merged 2 commits intoAug 14, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 21:50
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 21:51
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens ONNX Runtime graph robustness by adding centralized validation for initializers that use in-memory external data references, ensuring those references are properly backed by cached OrtValues (and match the expected in-memory pointer) before graph transformations that may copy initializer data.
Changes:
- Adds
Graph::ValidateInMemoryInitializers()and calls it early inInferenceSession::TransformGraph()to reject invalid/malicious in-memory initializer references before AOT inlining/partitioning. - Introduces a local
GetValidatedInMemoryInitializerhelper ingraph_utils.ccand routes relevant initializer-copy/inline-conversion paths through it. - Adds a regression test to ensure unregistered/arbitrary in-memory initializer references are rejected.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/ir/graph_test.cc | Adds coverage to reject copying/validating unregistered in-memory initializer references. |
| onnxruntime/core/session/inference_session.cc | Invokes the new in-memory initializer validation early in graph transformation. |
| onnxruntime/core/graph/graph.cc | Implements Graph::ValidateInMemoryInitializers() over graph + subgraphs. |
| onnxruntime/core/graph/graph_utils.cc | Adds a shared validation helper and uses it in initializer copy/inline-conversion paths. |
| include/onnxruntime/core/graph/graph.h | Declares Graph::ValidateInMemoryInitializers() in the public Graph interface (non-minimal builds). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
previously approved these changes
Aug 13, 2026
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 14, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/in-memory-external-data-validation
branch
August 14, 2026 17:36
Tianlei Wu (tianleiwu)
pushed a commit
that referenced
this pull request
Aug 17, 2026
This was referenced Aug 19, 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.
This pull request introduces stricter validation and error handling for initializers with in-memory external data references in ONNX Runtime's graph handling. The main goal is to ensure that all such references are properly registered and that their data matches expectations, preventing invalid model states and improving robustness. Additionally, new tests are added to verify these behaviors.
Validation and Error Handling Improvements:
ValidateInMemoryInitializersmethod to theGraphclass, which checks that all in-memory external data initializers have correspondingOrtValueobjects with matching data, and integrated this validation into the graph transformation process. [1] [2] [3]GetValidatedInMemoryInitializeringraph_utils.ccto enforce that in-memory external data initializers are registered and their data matches, replacing ad-hoc checks in various code paths.MakeInitializerCopyIfNotExistandConvertInMemoryDataToInlineto use the new validation helper, ensuring consistent and early detection of invalid initializer states. [1] [2]Testing Enhancements:
RejectsUnregisteredInMemoryInitializerCopytest to verify that the system correctly rejects initializers with arbitrary or unregistered in-memory references, both during validation and when attempting to copy such initializers.