Skip to content

Commit ce4447a

Browse files
committed
Fix NchwcTransformer null deref on node with unresolved schema (#28392)
1 parent 3718f7d commit ce4447a

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

onnxruntime/core/graph/graph_utils.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,14 @@ bool IsSupportedOptypeVersionAndDomain(const Node& node,
396396
bool IsSupportedOptypeVersionAndDomain(const Node& node, std::string_view op_type,
397397
gsl::span<const ONNX_NAMESPACE::OperatorSetVersion> versions,
398398
std::string_view domain) {
399+
#if !defined(ORT_MINIMAL_BUILD)
400+
// node.Op() can be null for a node whose schema is not yet resolved.
401+
const auto* op_schema = node.Op();
402+
#endif
399403
return (node.OpType() == op_type &&
400404
// we don't have op schemas in the minimal build so there's no way to check the deprecated flag
401405
#if !defined(ORT_MINIMAL_BUILD)
402-
!node.Op()->Deprecated() &&
406+
op_schema != nullptr && !op_schema->Deprecated() &&
403407
#endif
404408
MatchesOpSinceVersion(node, versions) && MatchesOpSetDomain(node, domain));
405409
}

onnxruntime/test/optimizer/nchwc_optimizer_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ void NchwcOptimizerTester(const std::function<void(NchwcTestHelper& helper)>& bu
236236

237237
#ifndef DISABLE_CONTRIB_OPS
238238

239+
// Regression test for #28392: NchwcTransformer must not crash when a node's schema is unresolved (node.Op() == nullptr).
240+
TEST(NchwcOptimizerTests, MatMulCastDoesNotCrashOnUnresolvedSchema) {
241+
SessionOptions session_options;
242+
session_options.graph_optimization_level = TransformerLevel::Level3;
243+
session_options.session_logid = "NchwcOptimizerTests";
244+
InferenceSessionWrapper session{session_options, GetEnvironment()};
245+
ASSERT_STATUS_OK(session.Load(ORT_TSTR("testdata/transform/transpose_cast_matmul_fp16.onnx")));
246+
ASSERT_STATUS_OK(session.Initialize());
247+
}
248+
239249
TEST(NchwcOptimizerTests, ConvNchw) {
240250
auto test_case = [&](const std::string& activation_op_type) {
241251
auto build_test_case = [&](NchwcTestHelper& helper) {
762 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)