summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestValidation.cpp
diff options
context:
space:
mode:
authorSlava Shklyaev <slavash@google.com>2020-03-23 16:50:36 +0000
committerSlava Shklyaev <slavash@google.com>2020-03-26 17:35:34 +0000
commit699000b7da5d2b7a846644a369b4ccb91f68598c (patch)
treed36358f77298fdf1f6728e36c6a3e493caca139b /nn/runtime/test/TestValidation.cpp
parent0219d5233beedd92d3326a29d461183501374aae (diff)
downloadml-699000b7da5d2b7a846644a369b4ccb91f68598c.tar.gz
Catch integer overflow in getSizeOfData()
Bug: 146044137 Test: NNT_static Change-Id: Idd6a070b379c6f5b10105647ec93579320c558f3
Diffstat (limited to 'nn/runtime/test/TestValidation.cpp')
-rw-r--r--nn/runtime/test/TestValidation.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/nn/runtime/test/TestValidation.cpp b/nn/runtime/test/TestValidation.cpp
index c91b02d47..fefe5a6f5 100644
--- a/nn/runtime/test/TestValidation.cpp
+++ b/nn/runtime/test/TestValidation.cpp
@@ -542,6 +542,17 @@ TEST_F(ValidationTestModelExtensions, SetOperandValue_UnspecifiedRank) {
EXPECT_EQ(ANeuralNetworksModel_setOperandValue(mModel, operandIndex, buffer, sizeof(buffer)),
ANEURALNETWORKS_BAD_DATA);
}
+
+TEST_F(ValidationTestModelExtensions, AddOperandDimensionProductOverflow) {
+ uint32_t dimensions[] = {5, 4, 4, 786433, 5, 3, 16777216, 4, 5};
+ ANeuralNetworksOperandType operandType = {
+ .type = getExtensionOperandType(kTestExtensionTensorType),
+ .dimensionCount = std::size(dimensions),
+ .dimensions = dimensions,
+ };
+ // This should fail, as the operand type's dimension product overflows uint32_t.
+ ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &operandType), ANEURALNETWORKS_BAD_DATA);
+}
#endif
TEST_F(ValidationTestModel, SetOptionalOperand) {
@@ -1900,6 +1911,17 @@ TEST_F(ValidationTestDimensionProductOverflow, SetInputOrOutput) {
ANEURALNETWORKS_BAD_DATA);
}
+TEST_F(ValidationTestModel, AddOperandDimensionProductOverflow) {
+ uint32_t dimensions[] = {5, 4, 4, 786433, 5, 3, 16777216, 4, 5};
+ ANeuralNetworksOperandType operandType = {
+ .type = ANEURALNETWORKS_TENSOR_FLOAT32,
+ .dimensionCount = std::size(dimensions),
+ .dimensions = dimensions,
+ };
+ // This should fail, as the operand type's dimension product overflows uint32_t.
+ ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &operandType), ANEURALNETWORKS_BAD_DATA);
+}
+
TEST_F(ValidationTestBurst, BurstComputeNull) {
EXPECT_EQ(ANeuralNetworksExecution_burstCompute(mExecution, nullptr),
ANEURALNETWORKS_UNEXPECTED_NULL);