First attempt at a Python fuzzer.
Using the following as a guide: https://google.github.io/oss-fuzz/getting-started/new-project-guide/python-lang/ PiperOrigin-RevId: 351239322 Change-Id: I91df8559d00f00e35ffdaec0960abe1b0a4462b1
This commit is contained in:
parent
6dc9dc2334
commit
084b4abb12
@ -5,6 +5,7 @@
|
||||
load(
|
||||
"//tensorflow/security/fuzzing:tf_fuzzing.bzl",
|
||||
"tf_fuzz_target",
|
||||
"tf_py_fuzz_target",
|
||||
)
|
||||
|
||||
package(
|
||||
@ -127,3 +128,12 @@ tf_fuzz_target(
|
||||
"//tensorflow/core/platform:stringpiece",
|
||||
],
|
||||
)
|
||||
|
||||
tf_py_fuzz_target(
|
||||
name = "constant_fuzz",
|
||||
srcs = ["constant_fuzz.py"],
|
||||
tags = ["notap"], # Run in OSS only.
|
||||
deps = [
|
||||
"//tensorflow/python:constant_op",
|
||||
],
|
||||
)
|
||||
|
31
tensorflow/security/fuzzing/constant_fuzz.py
Normal file
31
tensorflow/security/fuzzing/constant_fuzz.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright 2020 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.constant."""
|
||||
import sys
|
||||
import atheris_no_libfuzzer as atheris
|
||||
from tensorflow.python.framework import constant_op
|
||||
|
||||
|
||||
def TestOneInput(data):
|
||||
constant_op.constant(data)
|
||||
|
||||
|
||||
def main():
|
||||
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
|
||||
atheris.Fuzz()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -79,3 +79,63 @@ def tf_fuzz_target(
|
||||
linkstatic = 1,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
# tf_py_fuzz_target is a py_test modified to include fuzzing support.
|
||||
def tf_py_fuzz_target(
|
||||
name,
|
||||
# Fuzzing specific arguments
|
||||
fuzzing_dict = [],
|
||||
corpus = [],
|
||||
parsers = [],
|
||||
# Reporting bugs arguments, not used in open source
|
||||
componentid = None,
|
||||
hotlists = [],
|
||||
# Additional py_test control
|
||||
data = [],
|
||||
deps = [],
|
||||
tags = [],
|
||||
# Remaining py_test arguments
|
||||
**kwargs):
|
||||
"""Specify how to build a TensorFlow Python fuzz target.
|
||||
|
||||
Args:
|
||||
name: Mandatory name of the fuzzer target.
|
||||
|
||||
fuzzing_dict: An optional a set of dictionary files following
|
||||
the AFL/libFuzzer dictionary syntax.
|
||||
|
||||
corpus: An optional set of files used as the initial test corpus
|
||||
for the target. When doing "bazel test" in the default null-fuzzer
|
||||
(unittest) mode, these files are automatically passed to the target
|
||||
function.
|
||||
|
||||
parsers: An optional list of file extensions that the target supports.
|
||||
Used by tools like autofuzz to reuse corpus sets across targets.
|
||||
|
||||
componentid: Used internally for reporting fuzz discovered bugs.
|
||||
|
||||
hotlists: Used internally for reporting fuzz discovered bugs.
|
||||
|
||||
data: Additional data dependencies passed to the underlying py_test rule.
|
||||
|
||||
deps: An optional list of dependencies for the code you're fuzzing.
|
||||
|
||||
tags: Additional tags passed to the underlying py_test rule.
|
||||
|
||||
**kwargs: Collects all remaining arguments and passes them to the
|
||||
underlying py_test rule generated by the macro.
|
||||
"""
|
||||
componentid = None
|
||||
hotlists = None
|
||||
|
||||
# Fuzzers in open source must be run manually
|
||||
tags = tags + ["manual"]
|
||||
|
||||
# Now, redirect to py_test
|
||||
native.py_test(
|
||||
name = name,
|
||||
deps = deps,
|
||||
data = data,
|
||||
tags = tags,
|
||||
**kwargs
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user