diff options
author | David Monahan <david.monahan@arm.com> | 2023-07-28 11:37:29 +0100 |
---|---|---|
committer | David Monahan <david.monahan@arm.com> | 2023-07-28 11:37:29 +0100 |
commit | 39085f76e7a028d732c1ccdd07dcaa5d46e5ffb6 (patch) | |
tree | a6b4c1326ad39dc7468760473c1df31a83f394da | |
parent | 92ce35cda7c5e97eff05d6f37dc86990386309bb (diff) | |
download | armnn-39085f76e7a028d732c1ccdd07dcaa5d46e5ffb6.tar.gz |
IVGCVSW-7860 - Fix segfault with some models in the TfLiteParser
* Added boilerplate checks around the ParseStridedSlice memcpy's
Signed-off-by: David Monahan <david.monahan@arm.com>
Change-Id: Ied85c709dee230eb2984d3e339ed711d62ab36bd
-rw-r--r-- | src/armnnTfLiteParser/TfLiteParser.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index a6d651f5ab..c0e52b2113 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -2389,19 +2389,41 @@ void TfLiteParserImpl::ParseStridedSlice(size_t subgraphIndex, size_t operatorIn BufferRawPtr beginBufferPtr = GetBuffer(m_Model, inputs[1]->buffer); std::vector<int> begin(beginTensorInfo.GetNumElements()); - ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.GetNumBytes()); + if (beginBufferPtr->data.data() != nullptr) + { + ::memcpy(begin.data(), beginBufferPtr->data.data(), beginTensorInfo.GetNumBytes()); + } + else + { + throw ParseException("ParseStridedSlice: Invalid input - the begin vector is null"); + } armnn::TensorInfo endTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2); BufferRawPtr endBufferPtr = GetBuffer(m_Model, inputs[2]->buffer); std::vector<int> end(endTensorInfo.GetNumElements()); - ::memcpy(end.data(), endBufferPtr->data.data(), endTensorInfo.GetNumBytes()); + if (endBufferPtr->data.data() != nullptr) + { + ::memcpy(end.data(), endBufferPtr->data.data(), endTensorInfo.GetNumBytes()); + } + else + { + throw ParseException("ParseStridedSlice: Invalid input - the end vector is null"); + } armnn::TensorInfo strideTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 3); BufferRawPtr strideBufferPtr = GetBuffer(m_Model, inputs[3]->buffer); std::vector<int> stride(strideTensorInfo.GetNumElements()); - ::memcpy(stride.data(), strideBufferPtr->data.data(), strideTensorInfo.GetNumBytes()); + + if (strideBufferPtr->data.data() != nullptr) + { + ::memcpy(stride.data(), strideBufferPtr->data.data(), strideTensorInfo.GetNumBytes()); + } + else + { + throw ParseException("ParseStridedSlice: Invalid input - the stride vector is null"); + } desc.m_Begin = begin; desc.m_End = end; |