Create a fuzzer for JoinPath.

PiperOrigin-RevId: 345132114
Change-Id: Ief54aa3e761dbcf89100c42587ee468886f0d5da
This commit is contained in:
Amit Patankar 2020-12-01 17:18:47 -08:00 committed by TensorFlower Gardener
parent 06f6587733
commit 5e0f094382
3 changed files with 55 additions and 1 deletions

View File

@ -27,6 +27,15 @@ tf_fuzz_target(
],
)
tf_fuzz_target(
name = "joinpath_fuzz",
srcs = ["joinpath_fuzz.cc"],
deps = [
"//tensorflow/core/platform:path",
"@com_google_absl//absl/strings",
],
)
tf_fuzz_target(
name = "parseURI_fuzz",
srcs = ["parseURI_fuzz.cc"],

View File

@ -0,0 +1,45 @@
/* 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/platform/path.h"
// This is a fuzzer for tensorflow::io::JoinPath.
namespace {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
// Choose random numbers here.
const int content_size = fuzzed_data.ConsumeIntegralInRange(10, 300);
std::string first = fuzzed_data.ConsumeRandomLengthString(content_size);
std::string second = fuzzed_data.ConsumeRemainingBytesAsString();
std::string path = tensorflow::io::JoinPath(first, second);
// Assert path contains strings
assert(absl::StrContains(path, first));
assert(absl::StrContains(path, second));
return 0;
}
} // namespace

View File

@ -20,7 +20,7 @@ limitations under the License.
#include "tensorflow/core/platform/path.h"
#include "tensorflow/core/platform/stringpiece.h"
// This is a fuzzer for tensorflow::io::CleanPath.
// This is a fuzzer for tensorflow::io::ParseURI.
namespace {