Skip to content

Commit 24f2767

Browse files
committed
fix: out of bounds access in Dimensions::collapse()
Reworks Dimensions::collapse() to use iterators instead of dereferencing and using address-of operator. In some cases it would dereference out of bounds, leading to UB. Resolves: COMPMID-8060 Change-Id: Idba97c23e3fd4d776b62b02e4afc6a29e34aa72a Signed-off-by: Dennis Wildmark <[email protected]> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/14654 Benchmark: Arm Jenkins <[email protected]> Reviewed-by: Gunes Bayir <[email protected]> Comments-Addressed: Arm Jenkins <[email protected]> Tested-by: Arm Jenkins <[email protected]>
1 parent d6b604d commit 24f2767

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arm_compute/core/Dimensions.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,17 @@ class Dimensions
167167

168168
if (last > (first + 1))
169169
{
170+
auto it_first = _id.begin() + first;
171+
auto it_last = _id.begin() + last;
170172
// Collapse dimensions into the first
171-
_id[first] = std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
173+
_id[first] = std::accumulate(it_first, it_last, 1, std::multiplies<T>());
172174
// Shift the remaining dimensions down
173-
std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
175+
std::copy(it_last, _id.begin() + _num_dimensions, it_first + 1);
174176
// Reduce the number of dimensions
175177
const size_t old_num_dimensions = _num_dimensions;
176178
_num_dimensions -= last - first - 1;
177179
// Fill the now empty dimensions with zero
178-
std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
180+
std::fill(_id.begin() + _num_dimensions, _id.begin() + old_num_dimensions, 0);
179181
}
180182
}
181183

0 commit comments

Comments
 (0)