From 856992a6406168825193f8d409954629cf523b3f Mon Sep 17 00:00:00 2001 From: Omar Al Khatib Date: Fri, 27 Feb 2026 14:16:16 +0000 Subject: [PATCH] fix: Use std::min in NECropKernel in addition to asserts-only macro to ensure valid index in production builds. Resolves: [COMPMID-8702] Signed-off-by: Omar Al Khatib Change-Id: I0c7666244d5166b08cf06bf23fd15147d7d37a49 --- src/core/NEON/kernels/NECropKernel.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/NEON/kernels/NECropKernel.cpp b/src/core/NEON/kernels/NECropKernel.cpp index cffc701348..d98c3b7875 100644 --- a/src/core/NEON/kernels/NECropKernel.cpp +++ b/src/core/NEON/kernels/NECropKernel.cpp @@ -38,6 +38,8 @@ #include "src/core/utils/helpers/bit_ops.h" #include "src/cpu/kernels/crop/list.h" +#include + namespace arm_compute { namespace @@ -323,9 +325,11 @@ void NECropKernel::run(const Window &window, const ThreadInfo &info) const auto *uk = get_implementation(CropSelectorData{_input->info()->data_type()}); - uint32_t batch_index = *(reinterpret_cast(_box_ind->ptr_to_element(Coordinates(_crop_box_ind)))); - ARM_COMPUTE_ERROR_ON(batch_index >= - _input->info()->tensor_shape()[3]); // Check if batch_index is outside the number of batches + uint32_t batch_index = + std::min(static_cast(_input->info()->tensor_shape()[3]), + *(reinterpret_cast(_box_ind->ptr_to_element(Coordinates(_crop_box_ind))))); + + ARM_COMPUTE_ERROR_ON(batch_index >= _input->info()->tensor_shape()[3]); Coordinates input_offset( 0, _end[0] < _start[0] ? _start[0] - _cols_out_of_bounds[0] : _start[0] + _cols_out_of_bounds[0],