int ModelArgumentInfo::updateDimensionInfo(const Operand& operand,
const ANeuralNetworksOperandType* newType) {
+ nnAssert(dimensions.empty());
if (newType == nullptr) {
- dimensions = hidl_vec<uint32_t>();
+ 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<OperandType>(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<uint32_t>(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;