diff options
author | Lev Proleev <levp@google.com> | 2020-05-05 17:26:26 +0100 |
---|---|---|
committer | Lev Proleev <levp@google.com> | 2020-05-07 16:53:24 +0100 |
commit | 2a9f593d6ca8603175c8fe79a1376893de0f222a (patch) | |
tree | 9264bf116684f109cddddb18a0a578a24dce752e /nn/runtime/test/specs | |
parent | 55bee1c40e56f690de39bae8e47a4b6f9743086c (diff) | |
download | ml-2a9f593d6ca8603175c8fe79a1376893de0f222a.tar.gz |
Fix null ptr dereference in REDUCE_* cpu implementation
When asked to reduce across all dimensions, reduce would produce a
zero-sized tensor without dimensions and cause segmentation fault in the
implementation.
The change fixes the bug by making the op output a tensor of size [1] in
this case.
Also, updated the bug to clarify this behaviour.
Bug: 155508675
Test: NNTest_static
Change-Id: Ie98d8fa2e508255fd50f6bd8184dc323ba90fac8
Diffstat (limited to 'nn/runtime/test/specs')
6 files changed, 174 insertions, 0 deletions
diff --git a/nn/runtime/test/specs/V1_2/reduce_all_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_all_b155508675.mod.py new file mode 100644 index 000000000..f0fb40eda --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_all_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_BOOL8", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_BOOL8", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_ALL", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [False], + op2: [False], +}, model=model) diff --git a/nn/runtime/test/specs/V1_2/reduce_any_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_any_b155508675.mod.py new file mode 100644 index 000000000..67e955efc --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_any_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_BOOL8", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_BOOL8", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_ANY", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [False], + op2: [False], +}, model=model) diff --git a/nn/runtime/test/specs/V1_2/reduce_max_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_max_b155508675.mod.py new file mode 100644 index 000000000..72c8e6531 --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_max_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_FLOAT32", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_FLOAT32", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_MAX", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [3.0], + op2: [3.0], +}, model=model) diff --git a/nn/runtime/test/specs/V1_2/reduce_min_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_min_b155508675.mod.py new file mode 100644 index 000000000..0fb9c8ff9 --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_min_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_FLOAT32", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_FLOAT32", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_MIN", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [3.0], + op2: [3.0], +}, model=model) diff --git a/nn/runtime/test/specs/V1_2/reduce_prod_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_prod_b155508675.mod.py new file mode 100644 index 000000000..212c9b3d8 --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_prod_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_FLOAT32", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_FLOAT32", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_PROD", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [3.0], + op2: [3.0], +}, model=model) diff --git a/nn/runtime/test/specs/V1_2/reduce_sum_b155508675.mod.py b/nn/runtime/test/specs/V1_2/reduce_sum_b155508675.mod.py new file mode 100644 index 000000000..a2cb79df6 --- /dev/null +++ b/nn/runtime/test/specs/V1_2/reduce_sum_b155508675.mod.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Model operands +op1 = Input("op1", ["TENSOR_FLOAT32", [1, 1, 1]]) +op2 = Output("op2", ["TENSOR_FLOAT32", [1]]) + +# Model operations +model = Model() +model.Operation("REDUCE_SUM", op1, [0, 1, 2], False).To(op2) + +# Example +Example({ + op1: [3.0], + op2: [3.0], +}, model=model) |