onnxruntime
79fc8c60 - Limit nested model graph depth (#32344)

Commit
4 days ago
Limit nested model graph depth (#32344) This pull request introduces a validation step to limit the maximum allowed subgraph nesting depth in ONNX models to 32. This prevents excessively deep or recursive subgraph structures that could cause stack overflows or performance issues. The change is enforced during model loading and is covered by new unit tests. **Model validation enhancements:** * Added a new function `ValidateModelSubgraphDepth` that checks the nesting depth of subgraphs in a model and returns an error if the depth exceeds `kMaxModelSubgraphDepth` (32). [[1]](diffhunk://#diff-e1f6b61449afbbdbd824e4eef1019d66b329a821db67db46b9f06e011369a8deR67-R98) [[2]](diffhunk://#diff-a53ff461ebc52d6d228c126597a017c9d757b899f3244a795ab2118e41f29444R26-R29) * Integrated `ValidateModelSubgraphDepth` into the `Model` constructor to enforce subgraph depth checks during model loading. [[1]](diffhunk://#diff-27dfc51b4b723d56e08b54409b60a5d7a689f3908c2208385449435ad3db9641R139) [[2]](diffhunk://#diff-27dfc51b4b723d56e08b54409b60a5d7a689f3908c2208385449435ad3db9641R274) **Testing improvements:** * Added unit tests to verify that models with excessive subgraph depth are correctly rejected, and that the depth limit is enforced for both regular subgraphs and those in local functions. [[1]](diffhunk://#diff-c78e822207193cf3dbd4c9b5630ed0da508286c156454770d8c8b74d3047d317R447-R475) [[2]](diffhunk://#diff-1d3978c99d95a56af0f2603bdd0b10cf02bdc1cecbd4fe5db353a8c8388696efR3880-R3905) * Included necessary header for `model_helpers.h` in test files to support new validation logic. **API and constant definition:** * Introduced the constant `kMaxModelSubgraphDepth` in `model_helpers.h` to define the supported subgraph depth limit. * Declared the new validation function in the header for use across the codebase. [[1]](diffhunk://#diff-a53ff461ebc52d6d228c126597a017c9d757b899f3244a795ab2118e41f29444R26-R29) [[2]](diffhunk://#diff-a53ff461ebc52d6d228c126597a017c9d757b899f3244a795ab2118e41f29444R17)
Author
Parents
Loading