Skip to content

Commit 87863af

Browse files
committed
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 <omar.alkhatib@arm.com> Change-Id: I0c7666244d5166b08cf06bf23fd15147d7d37a49
1 parent 7844978 commit 87863af

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/core/NEON/kernels/NECropKernel.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "src/core/utils/helpers/bit_ops.h"
3939
#include "src/cpu/kernels/crop/list.h"
4040

41+
#include <algorithm>
42+
4143
namespace arm_compute
4244
{
4345
namespace
@@ -323,9 +325,11 @@ void NECropKernel::run(const Window &window, const ThreadInfo &info)
323325

324326
const auto *uk = get_implementation(CropSelectorData{_input->info()->data_type()});
325327

326-
uint32_t batch_index = *(reinterpret_cast<int32_t *>(_box_ind->ptr_to_element(Coordinates(_crop_box_ind))));
327-
ARM_COMPUTE_ERROR_ON(batch_index >=
328-
_input->info()->tensor_shape()[3]); // Check if batch_index is outside the number of batches
328+
uint32_t batch_index =
329+
std::min(static_cast<uint32_t>(_input->info()->tensor_shape()[3]),
330+
*(reinterpret_cast<uint32_t *>(_box_ind->ptr_to_element(Coordinates(_crop_box_ind)))));
331+
332+
ARM_COMPUTE_ERROR_ON(batch_index >= _input->info()->tensor_shape()[3]);
329333

330334
Coordinates input_offset(
331335
0, _end[0] < _start[0] ? _start[0] - _cols_out_of_bounds[0] : _start[0] + _cols_out_of_bounds[0],

0 commit comments

Comments
 (0)