|
| 1 | +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +==============================================================================*/ |
| 15 | + |
| 16 | +#include <cstdint> |
| 17 | +#include <cstdlib> |
| 18 | + |
| 19 | +#include "absl/strings/match.h" |
| 20 | +#include "tensorflow/core/platform/path.h" |
| 21 | +#include "tensorflow/core/platform/stringpiece.h" |
| 22 | + |
| 23 | +// This is a fuzzer for tensorflow::io::CleanPath. |
| 24 | + |
| 25 | +namespace { |
| 26 | + |
| 27 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 28 | + std::string uri(reinterpret_cast<const char *>(data), size); |
| 29 | + tensorflow::StringPiece scheme, host, path; |
| 30 | + tensorflow::io::ParseURI(uri, &scheme, &host, &path); |
| 31 | + |
| 32 | + // If a path is invalid. |
| 33 | + if (path == uri) { |
| 34 | + assert(host == ""); |
| 35 | + assert(scheme == ""); |
| 36 | + } else { |
| 37 | + assert(absl::StrContains(uri, host)); |
| 38 | + assert(absl::StrContains(uri, scheme)); |
| 39 | + assert(absl::StrContains(uri, path)); |
| 40 | + assert(absl::StrContains(uri, "://")); |
| 41 | + } |
| 42 | + |
| 43 | + return 0; |
| 44 | +} |
| 45 | + |
| 46 | +} // namespace |
0 commit comments