Skip to content

Commit 37cfaab

Browse files
Amit Patankartensorflower-gardener
authored andcommitted
Create a fuzzer for parseURI.
PiperOrigin-RevId: 343567698 Change-Id: I8a99ccf50c102c3468905a5460677f0dc533cab0
1 parent 1b00a12 commit 37cfaab

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎tensorflow/security/fuzzing/BUILD‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ tf_fuzz_target(
2727
],
2828
)
2929

30+
tf_fuzz_target(
31+
name = "parseURI_fuzz",
32+
srcs = ["parseURI_fuzz.cc"],
33+
deps = [
34+
"//tensorflow/core/platform:path",
35+
"//tensorflow/core/platform:stringpiece",
36+
"@com_google_absl//absl/strings",
37+
],
38+
)
39+
3040
tf_fuzz_target(
3141
name = "cleanpath_fuzz",
3242
srcs = ["cleanpath_fuzz.cc"],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)