Add extra handling for invalid ORT format model. - #29048
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens ORT-format model loading against semantically corrupt FlatBuffers content by converting previously-crashing null dereferences/assertions into clean Status failures with actionable error messages. It also adds targeted regression tests that construct minimal ORT-format FlatBuffers by hand to validate the new rejection paths.
Changes:
- Add validation in
Graph::LoadFromOrtFormatto rejectNodeEdgeentries that reference an unpopulated node slot. - Add validation in
Node::LoadEdgesFromOrtFormatto rejectEdgeEndreferences to missing nodes. - Add validation for graph inputs/outputs referencing unknown
NodeArgnames, and add regression tests for all three cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/test/ir/graph_test.cc | Adds regression tests that build minimal ORT-format FlatBuffers to ensure invalid graphs fail with clear errors instead of crashing. |
| onnxruntime/core/graph/graph.cc | Adds defensive null checks and clearer error returns for corrupt ORT-format edges and graph IO NodeArg references. |
|
This overlaps with #28186. @tianleiwu is there anything from this PR worth keeping? Maybe the tests? |
Pull request was closed
Add two regression tests for invalid ORT format models, covering the gaps not already exercised by this PR's existing tests: - RejectsEdgeEndReferencingNullNodeSlot: inner EdgeEnd referencing a within-range but unpopulated node slot - RejectsGraphInputWithUnknownNodeArg: graph input referencing an undeclared NodeArg name These consolidate the unique test coverage from microsoft#29048 (skottmckay) so that PR can be closed in favor of this one.
|
@skottmckay Thanks! I've consolidated the unique test coverage from this PR into #28186 (commit 23f9aa3). Comparing your three tests against the existing tests in 28186:
The graph.cc hardening overlaps with what 28186 already does, so I kept 28186's implementation and just folded in the missing test coverage. This PR can be closed in favor of #28186. |
Description
Improve handling for invalid ORT format model.
Motivation and Context
MSRC 119613