From 13c2101ecfefe898ed8efc801e57aad3f9818a10 Mon Sep 17 00:00:00 2001 From: danielsongmicrosoft Date: Sun, 27 Sep 2026 22:25:01 -0700 Subject: [PATCH] Reject recursive function graph attributes --- onnxruntime/core/graph/function_utils.cc | 105 ++++++++++-- onnxruntime/core/graph/function_utils.h | 6 +- onnxruntime/core/graph/graph.cc | 2 +- onnxruntime/test/framework/function_test.cc | 181 ++++++++++++++++++++ 4 files changed, 274 insertions(+), 20 deletions(-) diff --git a/onnxruntime/core/graph/function_utils.cc b/onnxruntime/core/graph/function_utils.cc index 7a851799454b0..eb9bc9c4440ef 100644 --- a/onnxruntime/core/graph/function_utils.cc +++ b/onnxruntime/core/graph/function_utils.cc @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#include +#include #include #include "core/graph/function_utils.h" @@ -15,6 +17,33 @@ namespace function_utils { using string = std::string; using namespace ONNX_NAMESPACE; +namespace { + +bool AttributeContainsSubgraphs(const AttributeProto& attr) { + return attr.has_g() || attr.graphs_size() > 0; +} + +std::string FormatAttributeReferenceChain(const std::vector& active_attr_refs, const std::string& next_attr_ref) { + std::ostringstream stream; + + for (size_t i = 0; i < active_attr_refs.size(); ++i) { + if (i != 0) { + stream << " -> "; + } + + stream << active_attr_refs[i]; + } + + if (!active_attr_refs.empty()) { + stream << " -> "; + } + + stream << next_attr_ref; + return stream.str(); +} + +} // namespace + // Utilify function to get the imported version of domain from opset imports // Returns -1 if requested domain is not found in the opset_imports template