diff --git a/tensorflow/core/kernels/fuzzing/BUILD b/tensorflow/core/kernels/fuzzing/BUILD index 2d8b734535c964bf4162838baa8ad65af4790423..fcaf1a8966bce8464807d8bf78f847f8bf079f28 100644 --- a/tensorflow/core/kernels/fuzzing/BUILD +++ b/tensorflow/core/kernels/fuzzing/BUILD @@ -68,3 +68,5 @@ tf_ops_fuzz_target_lib("decode_json_example") tf_oss_fuzz_corpus("decode_json_example") tf_oss_fuzz_dict("decode_json_example") + +tf_ops_fuzz_target_lib("check_numerics") diff --git a/tensorflow/core/kernels/fuzzing/check_numerics_fuzz.cc b/tensorflow/core/kernels/fuzzing/check_numerics_fuzz.cc new file mode 100644 index 0000000000000000000000000000000000000000..bcd299e30802360bc54f1ae186c6853641cd9323 --- /dev/null +++ b/tensorflow/core/kernels/fuzzing/check_numerics_fuzz.cc @@ -0,0 +1,50 @@ +/* Copyright 2016 Google Inc. 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 "tensorflow/cc/ops/array_ops.h" +#include "tensorflow/cc/ops/standard_ops.h" +#include "tensorflow/core/kernels/fuzzing/fuzz_session.h" + +namespace tensorflow { +namespace fuzzing { + +class FuzzCheckNumerics : public FuzzSession { + void BuildGraph(const Scope& scope) override { + auto input = + tensorflow::ops::Placeholder(scope.WithOpName("input1"), DT_FLOAT); + auto prefix = "Error: "; + (void)tensorflow::ops::CheckNumerics(scope.WithOpName("output"), input, + prefix); + } + + void FuzzImpl(const uint8_t* data, size_t size) override { + size_t ratio = sizeof(float) / sizeof(uint8_t); + size_t num_floats = size / ratio; + const float* float_data = reinterpret_cast(data); + + Tensor input_tensor(tensorflow::DT_FLOAT, + TensorShape({static_cast(size)})); + auto flat_tensor = input_tensor.flat(); + for (size_t i = 0; i < num_floats; i++) { + flat_tensor(i) = float_data[i]; + } + RunOneInput(input_tensor).IgnoreError(); + } +}; + +STANDARD_TF_FUZZ_FUNCTION(FuzzCheckNumerics); + +} // end namespace fuzzing +} // end namespace tensorflow