From de547168f108ec1494f18b3ab1ea50bd09f370c1 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Wed, 8 Mar 2023 10:08:20 +0000 Subject: IVGCVSW-7404 Out of bounds detection * Added test to ensure that all inputs and outputs do not go out of bounds. Signed-off-by: Mike Kelly Change-Id: Ia97e85f71e46cd2203306243e4dcbc23e0f29ec1 --- ArmnnPreparedModel_1_3.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'ArmnnPreparedModel_1_3.cpp') diff --git a/ArmnnPreparedModel_1_3.cpp b/ArmnnPreparedModel_1_3.cpp index 20b49f5d..ceeb3c48 100644 --- a/ArmnnPreparedModel_1_3.cpp +++ b/ArmnnPreparedModel_1_3.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // // Note: the ArmnnFencedExecutionCallback and code snippet in the executeFenced() function @@ -510,11 +510,20 @@ Return ArmnnPreparedModel_1_3::PrepareMemoryForIn for (unsigned int i = 0; i < request.inputs.size(); i++) { const auto& inputArg = request.inputs[i]; - armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i); // inputs (of type InputTensors) is composed of a vector of ConstTensors. // Therefore, set all TensorInfo isConstant parameters of input Tensors to true. inputTensorInfo.SetConstant(); + auto result = ValidateRequestArgument(request, + inputTensorInfo, + inputArg, + "input"); + + if (result != V1_3::ErrorStatus::NONE) + { + return result; + } + const armnn::Tensor inputTensor = GetTensorForRequestArgument(inputArg, inputTensorInfo, memPools); if (inputTensor.GetMemoryArea() == nullptr) @@ -540,15 +549,24 @@ Return ArmnnPreparedModel_1_3::PrepareMemoryForOu for (unsigned int i = 0; i < request.outputs.size(); i++) { const auto& outputArg = request.outputs[i]; - armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i); + auto result = ValidateRequestArgument(request, + outputTensorInfo, + outputArg, + "output"); + + if (result != V1_3::ErrorStatus::NONE) + { + return result; + } + const armnn::Tensor outputTensor = GetTensorForRequestArgument(outputArg, outputTensorInfo, memPools); + if (outputTensor.GetMemoryArea() == nullptr) { ALOGE("Cannot execute request. Error converting request output %u to tensor", i); return V1_3::ErrorStatus::GENERAL_FAILURE; } - const size_t outputSize = outputTensorInfo.GetNumBytes(); unsigned int count = 0; -- cgit v1.2.1