Skip to content

[Fix] Illegal memory access in GetOutputIndex with optional outputs#27301

Open
qti-mattsinc wants to merge 2 commits intomicrosoft:mainfrom
CodeLinaro:dev/mattsinc/fix-output-index-support-optional
Open

[Fix] Illegal memory access in GetOutputIndex with optional outputs#27301
qti-mattsinc wants to merge 2 commits intomicrosoft:mainfrom
CodeLinaro:dev/mattsinc/fix-output-index-support-optional

Conversation

@qti-mattsinc
Copy link
Contributor

@qti-mattsinc qti-mattsinc commented Feb 10, 2026

Description

  • Fix an access violation in GetOutputIndex.
  • Add related EpGraphTest UT.

Motivation and Context

  • When a non-trailing output is optional, its ValueInfo in GetOutputIndex may be null. The current implementation attempts to dereference the nullptr due to a missing check.
  • This bug is exposed if an EP calls ValueInfo_GetValueProducer on a value info whose producer has non-trailing optional outputs.
  • [Fix] illegal memory access in GetInputIndices with optional inputs #25881 previously fixed the analogous issue for GetInputIndices but not for GetOutputIndex

* When a non-trailing output is optional, its ValueInfo may be nullptr.
  The current implementation attempts to dereference the nullptr
  due to a missing check.
* This bug is exposed if an EP calls `ValueInfo_GetValueProducer` on
  a value info whose producer has non-trailing optional outputs.
* This commit adds the required check and a unit test.
gsl::span<const EpValueInfo* const> outputs = producer_node.GetOutputsSpan();

for (size_t i = 0; i < outputs.size(); i++) {
if (outputs[i] == nullptr) { // outputs == nullptr means the output is optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (outputs[i] == nullptr) { // outputs == nullptr means the output is optional
if (outputs[i] == nullptr) { // outputs[i] == nullptr means the output is a missing optional output

edgchen1
edgchen1 previously approved these changes Feb 13, 2026
@@ -0,0 +1,65 @@
from onnx import TensorProto, checker, helper, save, shape_inference

Check warning

Code scanning / lintrunner

RUFF-FORMAT/format Warning test

Run lintrunner -a to apply this patch.
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.

2 participants