From b4164a4bc411e43fcc29e95238b683f2e8ee2834 Mon Sep 17 00:00:00 2001 From: Uwez Khan Date: Wed, 1 Jul 2026 15:14:43 +0530 Subject: [PATCH] bound einsum subscript index before reading input shape --- modules/dnn/src/layers/einsum_layer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/layers/einsum_layer.cpp b/modules/dnn/src/layers/einsum_layer.cpp index b215fd749a..107860c3f8 100644 --- a/modules/dnn/src/layers/einsum_layer.cpp +++ b/modules/dnn/src/layers/einsum_layer.cpp @@ -953,6 +953,8 @@ void LayerEinsumImpl::processEquation(const std::vector& inputs) CV_CheckNE(letterIdx, -1, "The only permissible subscript labels are lowercase letters (a-z) and uppercase letters (A-Z)."); + CV_CheckLT(dim_count, rank, + "The Einsum subscripts string has an excessive number of subscript labels compared to the rank of the input."); int dimValue = shape[dim_count]; // The subscript label was not found in the global subscript label array @@ -980,8 +982,7 @@ void LayerEinsumImpl::processEquation(const std::vector& inputs) ++letter2count[letterIdx]; currTokenIndices.push_back(letter2index[letterIdx]); - CV_CheckLE(++dim_count, rank, - "The Einsum subscripts string has an excessive number of subscript labels compared to the rank of the input."); + ++dim_count; } }