From 2b8bd66d13b4826e06f4099dc0a16f711b74d446 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=88=98=EC=A7=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Thu, 26 Apr 2018 14:04:00 +0900 Subject: [PATCH] Add additional ANEURALNETWORKS_BAD_DATA check into updateDimensionInfo (#910) This commit adds additional ANEURALNETWORKS_BAD_DATA check into updateDimensionInfo. These codes have copied from android NN master branch(af63a36) Fix : #805 Signed-off-by: sjsujinkim --- .../nn/depend/libhidl/base/include/hidl/HidlSupport.h | 3 +++ src/runtime/ref/nn/runtime/ExecutionBuilder.cpp | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/runtime/ref/nn/depend/libhidl/base/include/hidl/HidlSupport.h b/src/runtime/ref/nn/depend/libhidl/base/include/hidl/HidlSupport.h index 1d5184e..bc8d56e 100644 --- a/src/runtime/ref/nn/depend/libhidl/base/include/hidl/HidlSupport.h +++ b/src/runtime/ref/nn/depend/libhidl/base/include/hidl/HidlSupport.h @@ -313,6 +313,9 @@ struct hidl_vec { static_assert(hidl_vec::kOffsetOfBuffer == 0, "wrong offset"); } + // Note, does not initialize primitive types. + hidl_vec(size_t size) : hidl_vec() { resize(size); } + hidl_vec(const hidl_vec &other) : hidl_vec() { *this = other; } diff --git a/src/runtime/ref/nn/runtime/ExecutionBuilder.cpp b/src/runtime/ref/nn/runtime/ExecutionBuilder.cpp index 37ad99e..333836e 100644 --- a/src/runtime/ref/nn/runtime/ExecutionBuilder.cpp +++ b/src/runtime/ref/nn/runtime/ExecutionBuilder.cpp @@ -60,17 +60,30 @@ int ModelArgumentInfo::setFromMemory(const Operand& operand, const ANeuralNetwor int ModelArgumentInfo::updateDimensionInfo(const Operand& operand, const ANeuralNetworksOperandType* newType) { + nnAssert(dimensions.empty()); if (newType == nullptr) { - dimensions = hidl_vec(); + for (auto i : operand.dimensions) { + if (i == 0) { + LOG(ERROR) << "Setting input/output with unspecified dimensions"; + return ANEURALNETWORKS_BAD_DATA; + } + } + dimensions = operand.dimensions; } else { uint32_t count = newType->dimensionCount; if (static_cast(newType->type) != operand.type || count != operand.dimensions.size()) { - LOG(ERROR) << "ANeuralNetworksExecution_setInput/Output incompatible types"; + LOG(ERROR) << "Setting input/output with incompatible types"; return ANEURALNETWORKS_BAD_DATA; } + dimensions = hidl_vec(count); for (uint32_t i = 0; i < count; i++) { - dimensions[i] = newType->dimensions[i]; + if (operand.dimensions[i] != 0 && operand.dimensions[i] != newType->dimensions[i]) { + LOG(ERROR) << "Overriding a fully specified dimension is disallowed"; + return ANEURALNETWORKS_BAD_DATA; + } else { + dimensions[i] = newType->dimensions[i]; + } } } return ANEURALNETWORKS_NO_ERROR; -- 2.7.4