Skip to content

Commit 54ee51d

Browse files
committed
Check for invalid node arg when loading ORT format model. A node arg would always have a valid string in an ORT created model so this requires manual editing of the model to make it invalid.
1 parent b214734 commit 54ee51d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

onnxruntime/core/graph/graph.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6483,7 +6483,9 @@ common::Status Graph::LoadFromOrtFormat(const onnxruntime::fbs::Graph& fbs_graph
64836483
ORT_RETURN_IF(nullptr == fbs_value_info, "NodeArg is missing. Invalid ORT format model.");
64846484
NodeArgInfo node_arg_info;
64856485
ORT_RETURN_IF_ERROR(fbs::utils::LoadValueInfoOrtFormat(*fbs_value_info, node_arg_info));
6486-
node_args_[fbs_value_info->name()->str()] = std::make_unique<NodeArg>(std::move(node_arg_info));
6486+
const auto* name = fbs_value_info->name();
6487+
ORT_RETURN_IF(name == nullptr, "NodeArg name is missing. Invalid ORT format model.");
6488+
node_args_[name->str()] = std::make_unique<NodeArg>(std::move(node_arg_info));
64876489
}
64886490
}
64896491

onnxruntime/test/framework/ort_model_only_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,16 @@ TEST(OrtModelOnlyTests, GithubIssue17000) {
592592
RunOrtModel(test_info);
593593
}
594594

595+
// ICM 31000000518041.
596+
TEST(OrtModelOnlyTests, NullNodeArgNameCheck) {
597+
auto ort_file = ORT_TSTR("testdata/icm-31000000518041.ort");
598+
599+
SessionOptions so;
600+
InferenceSessionWrapper session_object{so, GetEnvironment()};
601+
ASSERT_STATUS_NOT_OK_AND_HAS_SUBSTR(session_object.Load(ort_file),
602+
"NodeArg name is missing. Invalid ORT format model.");
603+
}
604+
595605
#if !defined(DISABLE_ML_OPS)
596606
// test that we can deserialize and run a previously saved ORT format model
597607
// for a model with sequence and map outputs
4.98 KB
Binary file not shown.

0 commit comments

Comments
 (0)