diff --git a/onnxruntime/core/providers/cpu/controlflow/if.cc b/onnxruntime/core/providers/cpu/controlflow/if.cc index a5fe3f02b2924..51d2fc8291e48 100644 --- a/onnxruntime/core/providers/cpu/controlflow/if.cc +++ b/onnxruntime/core/providers/cpu/controlflow/if.cc @@ -248,7 +248,12 @@ Status If::Compute(OpKernelContext* ctx) const { auto ctx_internal = static_cast(ctx); - auto condition = *ctx->Input(0)->Data(); + const auto& condition_tensor = *ctx->Input(0); + + ORT_RETURN_IF_NOT(condition_tensor.Shape().Size() == 1, + "If nodes condition input must have exactly one element"); + + auto condition = *condition_tensor.Data(); auto attribute = condition ? "then_branch" : "else_branch"; auto* session_state = ctx_internal->SubgraphSessionState(attribute);