From bddb2583f2fe3529787f55a4143b24db42951721 Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Tue, 23 Nov 2021 11:49:23 +0000 Subject: IVGCVSW-6610 No bounds checking performed when indexing PermutationVector elements. * Added out of bounds index error checking to PermutationVector operator[] method in Types.hpp. * Added armnn unit tests to UnitsTests.cpp to check error when using PermutationVector alone and with TransposeDescriptor and PermuteDescriptor. * Added pyarmnn unit test to check error when using PermutationVector. Signed-off-by: Cathal Corbett Change-Id: Ie5a8090f07b571a6bdf79a8cad621c31cc1891b7 --- include/armnn/Types.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index b5a4266e36..880a6dd816 100644 --- a/include/armnn/Types.hpp +++ b/include/armnn/Types.hpp @@ -306,7 +306,21 @@ public: PermutationVector(std::initializer_list dimMappings); - ValueType operator[](SizeType i) const { return m_DimMappings.at(i); } + /// + /// Indexing method with out-of-bounds error checking for the m_DimMappings array. + /// @param i - integer value corresponding to index of m_DimMappings array to retrieve element from. + /// @return element at index i of m_DimMappings array. + /// @throws InvalidArgumentException when indexing out-of-bounds index of m_DimMappings array. + /// + ValueType operator[](SizeType i) const + { + if (i >= GetSize()) + { + throw InvalidArgumentException("Invalid indexing of PermutationVector of size " + std::to_string(GetSize()) + + " at location [" + std::to_string(i) + "]."); + } + return m_DimMappings.at(i); + } SizeType GetSize() const { return m_NumDimMappings; } -- cgit v1.2.1