From f7d8f16fc5f5bb65c7606de30f27c11f1c4fa1ac Mon Sep 17 00:00:00 2001 From: Amit Patankar Date: Wed, 24 Feb 2021 15:18:11 -0800 Subject: [PATCH] Add a Python fuzzer for `tf.raw_ops.SparseCountSparseOutput`. PiperOrigin-RevId: 359381561 Change-Id: I546fd8791327fd9949b7b282b2f1d15fd7b47229 --- tensorflow/security/fuzzing/BUILD | 7 ++ .../fuzzing/sparseCountSparseOutput_fuzz.py | 65 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tensorflow/security/fuzzing/sparseCountSparseOutput_fuzz.py diff --git a/tensorflow/security/fuzzing/BUILD b/tensorflow/security/fuzzing/BUILD index 48f56d57bc5..8596361dbcb 100644 --- a/tensorflow/security/fuzzing/BUILD +++ b/tensorflow/security/fuzzing/BUILD @@ -166,3 +166,10 @@ tf_py_fuzz_target( tags = ["notap"], # Run in OSS only. deps = [":python_fuzzing"], ) + +tf_py_fuzz_target( + name = "sparseCountSparseOutput_fuzz", + srcs = ["sparseCountSparseOutput_fuzz.py"], + tags = ["notap"], # Run in OSS only. + deps = [":python_fuzzing"], +) diff --git a/tensorflow/security/fuzzing/sparseCountSparseOutput_fuzz.py b/tensorflow/security/fuzzing/sparseCountSparseOutput_fuzz.py new file mode 100644 index 00000000000..e19c7575d68 --- /dev/null +++ b/tensorflow/security/fuzzing/sparseCountSparseOutput_fuzz.py @@ -0,0 +1,65 @@ +# Copyright 2021 The TensorFlow Authors. All Rights Reserved. +# +# 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. +# ============================================================================== +"""This is a Python API fuzzer for tf.raw_ops.SparseCountSparseOutput.""" +import sys +import atheris_no_libfuzzer as atheris +from python_fuzzing import FuzzingHelper +import tensorflow as tf + + +def TestOneInput(input_bytes): + """Test randomized integer fuzzing input for tf.raw_ops.SparseCountSparseOutput.""" + fh = FuzzingHelper(input_bytes) + + shape1 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) + shape2 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) + shape3 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) + shape4 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) + + seed = fh.get_int() + indices = tf.random.uniform( + shape=shape1, minval=0, maxval=1000, dtype=tf.int64, seed=seed) + values = tf.random.uniform( + shape=shape2, minval=0, maxval=1000, dtype=tf.int64, seed=seed) + dense_shape = tf.random.uniform( + shape=shape3, minval=0, maxval=1000, dtype=tf.int64, seed=seed) + weights = tf.random.uniform( + shape=shape4, minval=0, maxval=1000, dtype=tf.int64, seed=seed) + + binary_output = fh.get_bool() + minlength = fh.get_int() + maxlength = fh.get_int() + name = fh.get_string() + try: + _, _, _, = tf.raw_ops.SparseCountSparseOutput( + indices=indices, + values=values, + dense_shape=dense_shape, + weights=weights, + binary_output=binary_output, + minlength=minlength, + maxlength=maxlength, + name=name) + except tf.errors.InvalidArgumentError: + pass + + +def main(): + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + + +if __name__ == "__main__": + main()