Create a fuzzer for AreAttrValuesEqual
and FastAreAttrValuesEqual
.
PiperOrigin-RevId: 348489985 Change-Id: I26bbb2ff4fb873498f2d89386244f96c9dfa5942
This commit is contained in:
parent
aee0999827
commit
9d10fa31f0
@ -37,7 +37,6 @@ load(
|
||||
package(
|
||||
default_visibility = [
|
||||
"//tensorflow/core:__subpackages__",
|
||||
"//tensorflow/security/fuzzing:__subpackages__",
|
||||
],
|
||||
licenses = ["notice"], # Apache 2.0
|
||||
)
|
||||
@ -1056,10 +1055,10 @@ tf_cc_test(
|
||||
size = "small",
|
||||
srcs = ["op_gen_lib_test.cc"],
|
||||
deps = [
|
||||
":op_gen_lib",
|
||||
"//tensorflow/core:protos_all_cc",
|
||||
"//tensorflow/core:test",
|
||||
"//tensorflow/core:test_main",
|
||||
"//tensorflow/core/framework:op_gen_lib",
|
||||
],
|
||||
)
|
||||
|
||||
@ -1109,7 +1108,6 @@ tf_cc_test(
|
||||
srcs = ["run_handler_test.cc"],
|
||||
linkstatic = tf_kernel_tests_linkstatic(),
|
||||
deps = [
|
||||
":tensor_testutil",
|
||||
"//tensorflow/core:core_cpu",
|
||||
"//tensorflow/core:direct_session_internal",
|
||||
"//tensorflow/core:framework_internal",
|
||||
@ -1119,6 +1117,7 @@ tf_cc_test(
|
||||
"//tensorflow/core:test",
|
||||
"//tensorflow/core:test_main",
|
||||
"//tensorflow/core:testlib",
|
||||
"//tensorflow/core/framework:tensor_testutil",
|
||||
"//tensorflow/core/kernels:cwise_op",
|
||||
"//tensorflow/core/kernels:matmul_op",
|
||||
"//third_party/eigen3",
|
||||
@ -1248,16 +1247,6 @@ cc_library(
|
||||
"//tensorflow/python:__pkg__",
|
||||
"//tensorflow/python/util:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
":api_def_proto_cc",
|
||||
":op_def_proto_cc",
|
||||
":tensor",
|
||||
"//tensorflow/core:core_stringpiece",
|
||||
"//tensorflow/core:framework",
|
||||
"//tensorflow/core:lib",
|
||||
"//tensorflow/core/lib/core:refcount",
|
||||
"//tensorflow/core/lib/core:status",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
@ -1,77 +0,0 @@
|
||||
/* 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.
|
||||
==============================================================================*/
|
||||
#include <fuzzer/FuzzedDataProvider.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "tensorflow/core/framework/attr_value.pb.h"
|
||||
#include "tensorflow/core/framework/attr_value_util.h"
|
||||
|
||||
// This is a fuzzer for AreAttrValuesEqual and FastAreAttrValuesEqual.
|
||||
|
||||
namespace {
|
||||
|
||||
// A few helpers to construct AttrValue protos.
|
||||
template <typename T>
|
||||
tensorflow::AttrValue createAttrValue(T value) {
|
||||
tensorflow::AttrValue ret;
|
||||
SetAttrValue(value, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// A helper to do the comparison asserts.
|
||||
template <typename T>
|
||||
void compareValues(T value, T value_2) {
|
||||
const tensorflow::AttrValue proto = createAttrValue(value);
|
||||
const tensorflow::AttrValue proto_same = createAttrValue(value);
|
||||
const tensorflow::AttrValue proto2 = createAttrValue(value_2);
|
||||
|
||||
// Assert that the Fast and Regular are true.
|
||||
assert(tensorflow::AreAttrValuesEqual(proto, proto_same));
|
||||
assert(tensorflow::FastAreAttrValuesEqual(proto, proto_same));
|
||||
// Assert that Fast and Regular for the random values.
|
||||
assert(tensorflow::AreAttrValuesEqual(proto, proto2) ==
|
||||
tensorflow::FastAreAttrValuesEqual(proto, proto2));
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
|
||||
// Choose random integers.
|
||||
const int random_int = fuzzed_data.ConsumeIntegralInRange(1, 100);
|
||||
const int random_int2 = fuzzed_data.ConsumeIntegralInRange(1, 1000);
|
||||
compareValues(random_int, random_int2);
|
||||
|
||||
// Choose random floats.
|
||||
const float random_float =
|
||||
fuzzed_data.ConsumeFloatingPointInRange(1.0f, 1000.0f);
|
||||
const float random_float2 =
|
||||
fuzzed_data.ConsumeFloatingPointInRange(1.0f, 1000.0f);
|
||||
compareValues(random_float, random_float2);
|
||||
|
||||
// Choose random strings.
|
||||
const int content_size = fuzzed_data.ConsumeIntegralInRange(10, 300);
|
||||
const std::string test_string =
|
||||
fuzzed_data.ConsumeRandomLengthString(content_size);
|
||||
const std::string test_string2 =
|
||||
fuzzed_data.ConsumeRemainingBytesAsString();
|
||||
compareValues(test_string, test_string2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
@ -27,16 +27,6 @@ tf_fuzz_target(
|
||||
],
|
||||
)
|
||||
|
||||
tf_fuzz_target(
|
||||
name = "AreAttrValuesEqual_fuzz",
|
||||
srcs = ["AreAttrValuesEqual_fuzz.cc"],
|
||||
deps = [
|
||||
"//tensorflow/core/framework:attr_value_proto_cc",
|
||||
"//tensorflow/core/framework:attr_value_util",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
tf_fuzz_target(
|
||||
name = "joinpath_fuzz",
|
||||
srcs = ["joinpath_fuzz.cc"],
|
||||
|
Loading…
Reference in New Issue
Block a user