From 2af3a2cdcdd94dc567e675634fd6dab9f8ffbfff Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 30 Aug 2019 14:49:30 +0900 Subject: [PATCH] Fix uncatched exception (#7058) Operand::operandSize() can throw exeception because sizeOfDataType() in DataType.h can throw runtime exception Signed-off-by: Hyeongseok Oh --- .../nnapi/wrapper/ANeuralNetworksExecution.cc | 30 +++++++++++++++++----- .../frontend/nnapi/wrapper/ANeuralNetworksModel.cc | 11 +++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc index 6598c61..3ac73a4 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc @@ -63,12 +63,21 @@ ANeuralNetworksExecution::getOutputOperandIndex(int32_t index) noexcept bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType *type, const neurun::model::OperandIndex index) noexcept { - const auto operand_type = _execution->model().operands.at(index).typeInfo(); - const auto typeInfo = NNAPIConvert::getTypeInfo(type); - - if (operand_type != typeInfo) + try + { + const auto operand_type = _execution->model().operands.at(index).typeInfo(); + const auto typeInfo = NNAPIConvert::getTypeInfo(type); + + if (operand_type != typeInfo) + { + // Data type mismatch + return false; + } + } + catch (const std::exception &e) { - // Data type mismatch + VERBOSE(EXCEPTION) << e.what() << std::endl; + return false; } @@ -99,7 +108,16 @@ bool ANeuralNetworksExecution::haveUnspecifiedDims(const neurun::model::OperandI size_t ANeuralNetworksExecution::getOperandSize(const neurun::model::OperandIndex index) noexcept { - return _execution->model().operands.at(index).operandSize(); + try + { + return _execution->model().operands.at(index).operandSize(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << std::endl; + + return 0; + } } bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOperandType *type, diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc index 268eb0c..e3bb291 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc @@ -214,7 +214,16 @@ bool ANeuralNetworksModel::isExistOperand(uint32_t index) noexcept size_t ANeuralNetworksModel::operandSize(uint32_t index) noexcept { - return _model->operands.at(neurun::model::OperandIndex{index}).operandSize(); + try + { + return _model->operands.at(neurun::model::OperandIndex{index}).operandSize(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << '\n'; + + return 0; + } } bool ANeuralNetworksModel::isUsageSet(uint32_t index) noexcept -- 2.7.4