Skip to content

Commit 5992655

Browse files
jenselofssonDongsung-arm
authored andcommitted
fix: Add index validation to CpuMaxUnpoolingLayerKernel
* Resolves COMPMID-8700 Signed-off-by: Jens Elofsson <jens.elofsson@arm.com> Change-Id: Ib62f0deefd01e4e9f0c0fc6e85a042002abdd908
1 parent 2644b97 commit 5992655

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

arm_compute/runtime/NEON/functions/NEMaxUnpoolingLayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2022, 2025 Arm Limited.
2+
* Copyright (c) 2020-2022, 2025-2026 Arm Limited.
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -76,7 +76,7 @@ class NEMaxUnpoolingLayer : public IFunction
7676
*
7777
* @param[in, out] input Source tensor. (Written to only when padding != 0) Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
7878
* @param[out] output Destination tensor. Data types supported: Same as @p input.
79-
* @param[out] indices The indices of the maximal values. Data type supported: U32.
79+
* @param[in] indices The indices of the maximal values. Data type supported: U32.
8080
* @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
8181
*/
8282
void configure(ITensor *input, ITensor *indices, ITensor *output, const PoolingLayerInfo &pool_info);

src/cpu/kernels/maxunpool/generic/neon/impl.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2023 Arm Limited.
2+
* Copyright (c) 2022-2023, 2026 Arm Limited.
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -27,6 +27,9 @@
2727
#include "arm_compute/core/Window.h"
2828

2929
#include "src/core/NEON/wrapper/wrapper.h"
30+
31+
#include <algorithm>
32+
3033
namespace arm_compute
3134
{
3235
namespace cpu
@@ -38,13 +41,14 @@ void max_unpooling(const ITensor *input, const ITensor *indices, ITensor *output
3841
Iterator indices_itr(indices, window);
3942
auto out_ptr = reinterpret_cast<T *>(output->buffer());
4043
const int out_stride_w = static_cast<int>(output->info()->strides_in_bytes()[3]);
44+
uint32_t slice_size = output->info()->tensor_shape().total_size_lower(3);
4145
execute_window_loop(
4246
window,
4347
[&](const Coordinates &id)
4448
{
45-
auto vindices = reinterpret_cast<uint32_t *>(indices_itr.ptr());
46-
auto vinput = reinterpret_cast<T *>(input_itr.ptr());
47-
out_ptr[id[3] * out_stride_w / sizeof(T) + *vindices] = *vinput;
49+
auto vindices = reinterpret_cast<uint32_t *>(indices_itr.ptr());
50+
auto vinput = reinterpret_cast<T *>(input_itr.ptr());
51+
out_ptr[id[3] * out_stride_w / sizeof(T) + std::min(slice_size - 1, *vindices)] = *vinput;
4852
},
4953
input_itr, indices_itr);
5054
}

0 commit comments

Comments
 (0)