From 39085f76e7a028d732c1ccdd07dcaa5d46e5ffb6 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Fri, 28 Jul 2023 11:37:29 +0100 Subject: IVGCVSW-7860 - Fix segfault with some models in the TfLiteParser * Added boilerplate checks around the ParseStridedSlice memcpy's Signed-off-by: David Monahan Change-Id: Ied85c709dee230eb2984d3e339ed711d62ab36bd --- src/armnnTfLiteParser/TfLiteParser.cpp | 28 +++++++++++++++++++++++++--- 1 file 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 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 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 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; -- cgit v1.2.1