Kitxuuu commited on
Commit
9879f8b
·
verified ·
1 Parent(s): 8989ae2

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/actions/run_fuzzers/action.yml +82 -0
  2. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/filesystem/__init__.py +107 -0
  3. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/__init__.py +179 -0
  4. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/github_api.py +109 -0
  5. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/github_api_test.py +41 -0
  6. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/upload.js +45 -0
  7. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/gitlab/__init__.py +133 -0
  8. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/gsutil/__init__.py +109 -0
  9. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/no_filestore/__init__.py +51 -0
  10. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/platform_config/prow.py +64 -0
  11. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/.clusterfuzzlite/build.sh +24 -0
  12. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/do_stuff_fuzzer.cpp +24 -0
  13. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/my_api.cpp +36 -0
  14. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/my_api.h +19 -0
  15. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/standalone_fuzz_target_runner.cpp +47 -0
  16. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/msan_crash_fuzzer_output.txt +39 -0
  17. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/.gitignore +1 -0
  18. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/generate_job.py +50 -0
  19. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/launcher.py +34 -0
  20. local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/run.py +50 -0
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/actions/run_fuzzers/action.yml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # action.yml
2
+ name: 'run-fuzzers'
3
+ description: 'Runs fuzz target binaries for a specified length of time.'
4
+ inputs:
5
+ oss-fuzz-project-name:
6
+ description: 'The OSS-Fuzz project name.'
7
+ required: true
8
+ language:
9
+ description: 'Programming language project is written in.'
10
+ required: false
11
+ default: 'c++'
12
+ fuzz-seconds:
13
+ description: 'The total time allotted for fuzzing in seconds.'
14
+ required: true
15
+ default: 600
16
+ dry-run:
17
+ description: 'If set, run the action without actually reporting a failure.'
18
+ default: false
19
+ sanitizer:
20
+ description: 'The sanitizer to run the fuzzers with.'
21
+ default: 'address'
22
+ mode:
23
+ description: |
24
+ The mode to run the fuzzers with ("code-change", "batch", "coverage", or "prune").
25
+ "code-change" is for fuzzing a pull request or commit.
26
+ "batch" is for non-interactive fuzzing of an entire project.
27
+ "coverage" is for coverage generation.
28
+ "prune" is for corpus pruning.
29
+ required: false
30
+ default: 'code-change'
31
+ github-token:
32
+ description: |
33
+ Token for GitHub API. WARNING: THIS SHOULD NOT BE USED IN PRODUCTION YET
34
+ You should use "secrets.GITHUB_TOKEN" in your workflow file, do not
35
+ hardcode the token.
36
+ TODO(https://github.com/google/oss-fuzz/pull/5841#discussion_r639393361):
37
+ Document locking this down.
38
+ required: false
39
+ report-unreproducible-crashes:
40
+ description: 'If True, then unreproducible crashes will be reported.'
41
+ required: false
42
+ default: False
43
+ minimize-crashes:
44
+ description: 'If True, reportable crashes will be minimized.'
45
+ required: false
46
+ default: False
47
+ parallel-fuzzing:
48
+ description: "Whether to use all available cores for fuzzing."
49
+ required: false
50
+ default: false
51
+ output-sarif:
52
+ description: "Whether to output fuzzing results to SARIF."
53
+ required: false
54
+ default: false
55
+ report-timeouts:
56
+ description: "Whether to report fails due to timeout."
57
+ required: false
58
+ default: true
59
+ report-ooms:
60
+ description: "Whether to report fails due to OOM."
61
+ required: false
62
+ default: true
63
+ runs:
64
+ using: 'docker'
65
+ image: '../../../run_fuzzers.Dockerfile'
66
+ env:
67
+ OSS_FUZZ_PROJECT_NAME: ${{ inputs.oss-fuzz-project-name }}
68
+ LANGUAGE: ${{ inputs.language }}
69
+ FUZZ_SECONDS: ${{ inputs.fuzz-seconds }}
70
+ DRY_RUN: ${{ inputs.dry-run}}
71
+ SANITIZER: ${{ inputs.sanitizer }}
72
+ MODE: ${{ inputs.mode }}
73
+ GITHUB_TOKEN: ${{ inputs.github-token }}
74
+ LOW_DISK_SPACE: 'True'
75
+ REPORT_UNREPRODUCIBLE_CRASHES: ${{ inputs.report-unreproducible-crashes }}
76
+ MINIMIZE_CRASHES: ${{ inputs.minimize-crashes }}
77
+ CIFUZZ_DEBUG: 'True'
78
+ CFL_PLATFORM: 'github'
79
+ PARALLEL_FUZZING: ${{ inputs.parallel-fuzzing }}
80
+ OUTPUT_SARIF: ${{ inputs.output-sarif }}
81
+ REPORT_TIMEOUTS: ${{ inputs.report-timeouts }}
82
+ REPORT_OOMS: ${{ inputs.report-ooms}}
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/filesystem/__init__.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
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
+ """Filestore implementation using a filesystem directory."""
15
+ import logging
16
+ import os
17
+ import shutil
18
+ import subprocess
19
+ import sys
20
+
21
+ from distutils import dir_util
22
+
23
+ # pylint: disable=wrong-import-position,import-error
24
+ sys.path.append(
25
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir,
26
+ os.pardir, os.pardir))
27
+ import filestore
28
+
29
+
30
+ def recursive_list_dir(directory):
31
+ """Returns list of all files in |directory|, including those in
32
+ subdirectories."""
33
+ files = []
34
+ for root, _, filenames in os.walk(directory):
35
+ for filename in filenames:
36
+ files.append(os.path.join(root, filename))
37
+ return files
38
+
39
+
40
+ class FilesystemFilestore(filestore.BaseFilestore):
41
+ """Filesystem implementation using a filesystem directory."""
42
+ BUILD_DIR = 'build'
43
+ CRASHES_DIR = 'crashes'
44
+ CORPUS_DIR = 'corpus'
45
+ COVERAGE_DIR = 'coverage'
46
+
47
+ def __init__(self, config):
48
+ super().__init__(config)
49
+ self._filestore_root_dir = self.config.platform_conf.filestore_root_dir
50
+
51
+ def _get_filestore_path(self, name, prefix_dir):
52
+ """Returns the filesystem path in the filestore for |name| and
53
+ |prefix_dir|."""
54
+ return os.path.join(self._filestore_root_dir, prefix_dir, name)
55
+
56
+ def _upload_directory(self, name, directory, prefix, delete=False):
57
+ filestore_path = self._get_filestore_path(name, prefix)
58
+ if os.path.exists(filestore_path):
59
+ initial_files = set(recursive_list_dir(filestore_path))
60
+ else:
61
+ initial_files = set()
62
+
63
+ # Make directory and any parents.
64
+ os.makedirs(filestore_path, exist_ok=True)
65
+ copied_files = set(dir_util.copy_tree(directory, filestore_path))
66
+ if not delete:
67
+ return True
68
+
69
+ files_to_delete = initial_files - copied_files
70
+ for file_path in files_to_delete:
71
+ os.remove(file_path)
72
+ return True
73
+
74
+ def _download_directory(self, name, dst_directory, prefix):
75
+ filestore_path = self._get_filestore_path(name, prefix)
76
+ return dir_util.copy_tree(filestore_path, dst_directory)
77
+
78
+ def upload_crashes(self, name, directory):
79
+ """Uploads the crashes at |directory| to |name|."""
80
+ return self._upload_directory(name, directory, self.CRASHES_DIR)
81
+
82
+ def upload_corpus(self, name, directory, replace=False):
83
+ """Uploads the crashes at |directory| to |name|."""
84
+ return self._upload_directory(name,
85
+ directory,
86
+ self.CORPUS_DIR,
87
+ delete=replace)
88
+
89
+ def upload_build(self, name, directory):
90
+ """Uploads the build located at |directory| to |name|."""
91
+ return self._upload_directory(name, directory, self.BUILD_DIR)
92
+
93
+ def upload_coverage(self, name, directory):
94
+ """Uploads the coverage report at |directory| to |name|."""
95
+ return self._upload_directory(name, directory, self.COVERAGE_DIR)
96
+
97
+ def download_corpus(self, name, dst_directory):
98
+ """Downloads the corpus located at |name| to |dst_directory|."""
99
+ return self._download_directory(name, dst_directory, self.CORPUS_DIR)
100
+
101
+ def download_build(self, name, dst_directory):
102
+ """Downloads the build with |name| to |dst_directory|."""
103
+ return self._download_directory(name, dst_directory, self.BUILD_DIR)
104
+
105
+ def download_coverage(self, name, dst_directory):
106
+ """Downloads the latest project coverage report."""
107
+ return self._download_directory(name, dst_directory, self.COVERAGE_DIR)
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/__init__.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Implementation of a filestore using Github actions artifacts."""
15
+ import logging
16
+ import os
17
+ import shutil
18
+ import sys
19
+ import tarfile
20
+ import tempfile
21
+
22
+ # pylint: disable=wrong-import-position,import-error
23
+ INFRA_DIR = os.path.abspath(
24
+ os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir,
25
+ os.path.pardir))
26
+ sys.path.append(INFRA_DIR)
27
+ OSS_FUZZ_ROOT_DIR = os.path.dirname(INFRA_DIR)
28
+
29
+ import utils
30
+ import http_utils
31
+ import filestore
32
+ from filestore.github_actions import github_api
33
+
34
+ UPLOAD_JS = os.path.join(os.path.dirname(__file__), 'upload.js')
35
+
36
+
37
+ def tar_directory(directory, archive_path):
38
+ """Tars a |directory| and stores archive at |archive_path|. |archive_path|
39
+ must end in .tar"""
40
+ assert archive_path.endswith('.tar')
41
+ # Do this because make_archive will append the extension to archive_path.
42
+ archive_path = os.path.splitext(archive_path)[0]
43
+
44
+ root_directory = os.path.abspath(directory)
45
+ shutil.make_archive(archive_path,
46
+ 'tar',
47
+ root_dir=root_directory,
48
+ base_dir='./')
49
+
50
+
51
+ class GithubActionsFilestore(filestore.BaseFilestore):
52
+ """Implementation of BaseFilestore using Github actions artifacts. Relies on
53
+ github_actions_toolkit for using the GitHub actions API and the github_api
54
+ module for using GitHub's standard API. We need to use both because the GitHub
55
+ actions API is the only way to upload an artifact but it does not support
56
+ downloading artifacts from other runs. The standard GitHub API does support
57
+ this however."""
58
+
59
+ ARTIFACT_PREFIX = 'cifuzz-'
60
+ BUILD_PREFIX = 'build-'
61
+ CRASHES_PREFIX = 'crashes-'
62
+ CORPUS_PREFIX = 'corpus-'
63
+ COVERAGE_PREFIX = 'coverage-'
64
+
65
+ def __init__(self, config):
66
+ super().__init__(config)
67
+ self.github_api_http_headers = github_api.get_http_auth_headers(config)
68
+
69
+ def _get_artifact_name(self, name):
70
+ """Returns |name| prefixed with |self.ARITFACT_PREFIX| if it isn't already
71
+ prefixed. Otherwise returns |name|."""
72
+ if name.startswith(self.ARTIFACT_PREFIX):
73
+ return name
74
+ return f'{self.ARTIFACT_PREFIX}{name}'
75
+
76
+ def _upload_directory(self, name, directory): # pylint: disable=no-self-use
77
+ """Uploads |directory| as artifact with |name|."""
78
+ name = self._get_artifact_name(name)
79
+ with tempfile.TemporaryDirectory() as temp_dir:
80
+ archive_path = os.path.join(temp_dir, name + '.tar')
81
+ tar_directory(directory, archive_path)
82
+ _raw_upload_directory(name, temp_dir)
83
+
84
+ def upload_crashes(self, name, directory):
85
+ """Uploads the crashes at |directory| to |name|."""
86
+ return _raw_upload_directory(self.CRASHES_PREFIX + name, directory)
87
+
88
+ def upload_corpus(self, name, directory, replace=False):
89
+ """Uploads the corpus at |directory| to |name|."""
90
+ # Not applicable as the the entire corpus is uploaded under a single
91
+ # artifact name.
92
+ del replace
93
+ return self._upload_directory(self.CORPUS_PREFIX + name, directory)
94
+
95
+ def upload_build(self, name, directory):
96
+ """Uploads the build at |directory| to |name|."""
97
+ return self._upload_directory(self.BUILD_PREFIX + name, directory)
98
+
99
+ def upload_coverage(self, name, directory):
100
+ """Uploads the coverage report at |directory| to |name|."""
101
+ return self._upload_directory(self.COVERAGE_PREFIX + name, directory)
102
+
103
+ def download_corpus(self, name, dst_directory): # pylint: disable=unused-argument,no-self-use
104
+ """Downloads the corpus located at |name| to |dst_directory|."""
105
+ return self._download_artifact(self.CORPUS_PREFIX + name, dst_directory)
106
+
107
+ def _find_artifact(self, name):
108
+ """Finds an artifact using the GitHub API and returns it."""
109
+ logging.debug('Listing artifacts.')
110
+ artifacts = self._list_artifacts()
111
+ artifact = github_api.find_artifact(name, artifacts)
112
+ logging.debug('Artifact: %s.', artifact)
113
+ return artifact
114
+
115
+ def _download_artifact(self, name, dst_directory):
116
+ """Downloads artifact with |name| to |dst_directory|. Returns True on
117
+ success."""
118
+ name = self._get_artifact_name(name)
119
+
120
+ with tempfile.TemporaryDirectory() as temp_dir:
121
+ if not self._raw_download_artifact(name, temp_dir):
122
+ logging.warning('Could not download artifact: %s.', name)
123
+ return False
124
+
125
+ artifact_tarfile_path = os.path.join(temp_dir, name + '.tar')
126
+ if not os.path.exists(artifact_tarfile_path):
127
+ logging.error('Artifact zip did not contain a tarfile.')
128
+ return False
129
+
130
+ # TODO(jonathanmetzman): Replace this with archive.unpack from
131
+ # libClusterFuzz so we can avoid path traversal issues.
132
+ with tarfile.TarFile(artifact_tarfile_path) as artifact_tarfile:
133
+ artifact_tarfile.extractall(dst_directory)
134
+ return True
135
+
136
+ def _raw_download_artifact(self, name, dst_directory):
137
+ """Downloads the artifact with |name| to |dst_directory|. Returns True on
138
+ success. Does not do any untarring or adding prefix to |name|."""
139
+ artifact = self._find_artifact(name)
140
+ if not artifact:
141
+ logging.warning('Could not find artifact: %s.', name)
142
+ return False
143
+ download_url = artifact['archive_download_url']
144
+ return http_utils.download_and_unpack_zip(
145
+ download_url, dst_directory, headers=self.github_api_http_headers)
146
+
147
+ def _list_artifacts(self):
148
+ """Returns a list of artifacts."""
149
+ return github_api.list_artifacts(self.config.project_repo_owner,
150
+ self.config.project_repo_name,
151
+ self.github_api_http_headers)
152
+
153
+ def download_build(self, name, dst_directory):
154
+ """Downloads the build with name |name| to |dst_directory|."""
155
+ return self._download_artifact(self.BUILD_PREFIX + name, dst_directory)
156
+
157
+ def download_coverage(self, name, dst_directory):
158
+ """Downloads the latest project coverage report."""
159
+ return self._download_artifact(self.COVERAGE_PREFIX + name, dst_directory)
160
+
161
+
162
+ def _upload_artifact_with_upload_js(name, artifact_paths, directory):
163
+ """Uploads the artifacts in |artifact_paths| that are located in |directory|
164
+ to |name|, using the upload.js script."""
165
+ command = [UPLOAD_JS, name, directory] + artifact_paths
166
+ _, _, retcode = utils.execute(command, location=OSS_FUZZ_ROOT_DIR)
167
+ return retcode == 0
168
+
169
+
170
+ def _raw_upload_directory(name, directory):
171
+ """Uploads the artifacts located in |directory| to |name|. Does not do any
172
+ tarring or adding prefixes to |name|."""
173
+ # Get file paths.
174
+ artifact_paths = []
175
+ for root, _, curr_file_paths in os.walk(directory):
176
+ for file_path in curr_file_paths:
177
+ artifact_paths.append(os.path.join(root, file_path))
178
+ logging.debug('Artifact paths: %s.', artifact_paths)
179
+ return _upload_artifact_with_upload_js(name, artifact_paths, directory)
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/github_api.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Module for dealing with the GitHub API. This is different from
15
+ github_actions_toolkit which only deals with the actions API. We need to use
16
+ both."""
17
+ import logging
18
+ import os
19
+ import sys
20
+
21
+ import requests
22
+
23
+ import filestore
24
+
25
+ # pylint: disable=wrong-import-position,import-error
26
+
27
+ sys.path.append(
28
+ os.path.join(__file__, os.path.pardir, os.path.pardir, os.path.pardir,
29
+ os.path.pardir))
30
+ import retry
31
+
32
+ _MAX_ITEMS_PER_PAGE = 100
33
+
34
+ _GET_ATTEMPTS = 3
35
+ _GET_BACKOFF = 1
36
+
37
+
38
+ def get_http_auth_headers(config):
39
+ """Returns HTTP headers for authentication to the API."""
40
+ authorization = f'token {config.token}'
41
+ return {
42
+ 'Authorization': authorization,
43
+ 'Accept': 'application/vnd.github.v3+json'
44
+ }
45
+
46
+
47
+ def _get_artifacts_list_api_url(repo_owner, repo_name):
48
+ """Returns the artifacts_api_url for |repo_name| owned by |repo_owner|."""
49
+ github_api_url = os.getenv('GITHUB_API_URL', 'https://api.github.com')
50
+ return (f'{github_api_url}/repos/{repo_owner}/'
51
+ f'{repo_name}/actions/artifacts')
52
+
53
+
54
+ @retry.wrap(_GET_ATTEMPTS, _GET_BACKOFF)
55
+ def _do_get_request(*args, **kwargs):
56
+ """Wrapped version of requests.get that does retries."""
57
+ return requests.get(*args, **kwargs)
58
+
59
+
60
+ def _get_items(url, headers):
61
+ """Generator that gets and yields items from a GitHub API endpoint (specified
62
+ by |URL|) sending |headers| with the get request."""
63
+ # Github API response pages are 1-indexed.
64
+ page_counter = 1
65
+
66
+ # Set to infinity so we run loop at least once.
67
+ total_num_items = float('inf')
68
+
69
+ item_num = 0
70
+ while item_num < total_num_items:
71
+ params = {'per_page': _MAX_ITEMS_PER_PAGE, 'page': str(page_counter)}
72
+ response = _do_get_request(url, params=params, headers=headers)
73
+ response_json = response.json()
74
+ if not response.status_code == 200:
75
+ # Check that request was successful.
76
+ logging.error('Request to %s failed. Code: %d. Response: %s',
77
+ response.request.url, response.status_code, response_json)
78
+ raise filestore.FilestoreError('Github API request failed.')
79
+
80
+ if total_num_items == float('inf'):
81
+ # Set proper total_num_items
82
+ total_num_items = response_json['total_count']
83
+
84
+ # Get the key for the items we are after.
85
+ keys = [key for key in response_json.keys() if key != 'total_count']
86
+ assert len(keys) == 1, keys
87
+ items_key = keys[0]
88
+
89
+ for item in response_json[items_key]:
90
+ yield item
91
+ item_num += 1
92
+
93
+ page_counter += 1
94
+
95
+
96
+ def find_artifact(artifact_name, artifacts):
97
+ """Find the artifact with the name |artifact_name| in |artifacts|."""
98
+ for artifact in artifacts:
99
+ # TODO(metzman): Handle multiple by making sure we download the latest.
100
+ if artifact['name'] == artifact_name and not artifact['expired']:
101
+ return artifact
102
+ return None
103
+
104
+
105
+ def list_artifacts(owner, repo, headers):
106
+ """Returns a generator of all the artifacts for |owner|/|repo|."""
107
+ url = _get_artifacts_list_api_url(owner, repo)
108
+ logging.debug('Getting artifacts from: %s', url)
109
+ return _get_items(url, headers)
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/github_api_test.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Tests for github_api."""
15
+ import os
16
+ import sys
17
+ import unittest
18
+
19
+ # pylint: disable=wrong-import-position,import-error
20
+ sys.path.append(
21
+ os.path.abspath(
22
+ os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir,
23
+ os.path.pardir)))
24
+
25
+ from filestore.github_actions import github_api
26
+ import test_helpers
27
+
28
+
29
+ class GetHttpAuthHeaders(unittest.TestCase):
30
+ """Tests for get_http_auth_headers."""
31
+
32
+ def test_get_http_auth_headers(self):
33
+ """Tests that get_http_auth_headers returns the correct result."""
34
+ token = 'example githubtoken'
35
+ run_config = test_helpers.create_run_config(token=token)
36
+ expected_headers = {
37
+ 'Authorization': f'token {token}',
38
+ 'Accept': 'application/vnd.github.v3+json',
39
+ }
40
+ self.assertEqual(expected_headers,
41
+ github_api.get_http_auth_headers(run_config))
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/github_actions/upload.js ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+ // Copyright 2021 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // Script for uploading an artifact. Returns 0 on success.
16
+ // Usage: upload.js <artifactName> <rootDirectory> <file 1>...<file N>
17
+
18
+ const fs = require('fs');
19
+ const { DefaultArtifactClient } = require('@actions/artifact');
20
+
21
+ const artifactClient = new DefaultArtifactClient();
22
+ const artifactName = process.argv[2];
23
+ const rootDirectory = process.argv[3]
24
+ const files = process.argv.slice(4);
25
+ const options = {
26
+ continueOnError: true
27
+ };
28
+
29
+ async function uploadArtifact() {
30
+ try {
31
+ const uploadResult = await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
32
+ console.log(uploadResult);
33
+ if (uploadResult.failedItems.length > 0) {
34
+ return 1;
35
+ }
36
+ return 0;
37
+ } catch (error) {
38
+ console.error('Error uploading artifact:', error);
39
+ return 1;
40
+ }
41
+ }
42
+
43
+ uploadArtifact().then(exitCode => {
44
+ process.exit(exitCode);
45
+ });
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/gitlab/__init__.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
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
+ """GitLab filestore implementation."""
15
+ import logging
16
+
17
+ import json
18
+ import os
19
+ import shutil
20
+ import tempfile
21
+
22
+ import filestore
23
+ import http_utils
24
+
25
+ # pylint: disable=no-self-use,unused-argument
26
+
27
+
28
+ class GitlabFilestore(filestore.BaseFilestore):
29
+ """Implementation of BaseFilestore using GitLab.
30
+ Needs a cache to upload and download builds.
31
+ Needs a git repository for corpus and coverage.
32
+ """
33
+
34
+ BUILD_PREFIX = 'build-'
35
+ CORPUS_PREFIX = 'corpus-'
36
+ COVERAGE_PREFIX = 'coverage-'
37
+ CRASHES_PREFIX = 'crashes-'
38
+
39
+ def __init__(self, config):
40
+ super().__init__(config)
41
+ self.artifacts_dir = self.config.platform_conf.artifacts_dir
42
+ self.cache_dir = self.config.platform_conf.cache_dir
43
+ if self.config.git_store_repo:
44
+ self.git_filestore = filestore.git.GitFilestore(config, None)
45
+ else:
46
+ self.git_filestore = None
47
+
48
+ def upload_crashes(self, name, directory):
49
+ """GitLab artifacts implementation of upload_crashes."""
50
+ # Upload crashes as job artifacts.
51
+ if os.listdir(directory):
52
+ dest_dir_artifacts = os.path.join(self.config.project_src_path,
53
+ self.artifacts_dir,
54
+ self.CRASHES_PREFIX + name)
55
+ logging.info('Uploading artifacts to %s.', dest_dir_artifacts)
56
+ shutil.copytree(directory, dest_dir_artifacts)
57
+
58
+ def upload_corpus(self, name, directory, replace=False):
59
+ """GitLab artifacts implementation of upload_corpus."""
60
+ # Use the git filestore if any.
61
+ if self.git_filestore:
62
+ self.git_filestore.upload_corpus(name, directory, replace)
63
+ return
64
+ # Fall back to cache.
65
+ dest_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
66
+ self.CORPUS_PREFIX + name)
67
+ logging.info('Copying from %s to cache %s.', directory, dest_dir_cache)
68
+ # Remove previous corpus from cache if any.
69
+ shutil.rmtree(dest_dir_cache, ignore_errors=True)
70
+ shutil.copytree(directory, dest_dir_cache, dirs_exist_ok=True)
71
+
72
+ def upload_build(self, name, directory):
73
+ """GitLab artifacts implementation of upload_build."""
74
+ # Puts build into the cache.
75
+ dest_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
76
+ self.BUILD_PREFIX + name)
77
+ logging.info('Copying from %s to cache %s.', directory, dest_dir_cache)
78
+ shutil.copytree(directory, dest_dir_cache, dirs_exist_ok=True)
79
+
80
+ def upload_coverage(self, name, directory):
81
+ """GitLab artifacts implementation of upload_coverage."""
82
+ # Use the git filestore.
83
+ if self.git_filestore:
84
+ self.git_filestore.upload_coverage(name, directory)
85
+ return
86
+ # Fall back to cache.
87
+ dest_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
88
+ self.COVERAGE_PREFIX + name)
89
+ logging.info('Copying from %s to cache %s.', directory, dest_dir_cache)
90
+ shutil.copytree(directory, dest_dir_cache, dirs_exist_ok=True)
91
+ # And also updates coverage reports as artifacts
92
+ # as it should not be too big.
93
+ dest_dir_artifacts = os.path.join(self.config.project_src_path,
94
+ self.artifacts_dir,
95
+ self.COVERAGE_PREFIX + name)
96
+ logging.info('Uploading artifacts to %s.', dest_dir_artifacts)
97
+ shutil.copytree(directory, dest_dir_artifacts)
98
+
99
+ def _copy_from_cache(self, src_dir_cache, dst_directory):
100
+ if not os.path.exists(src_dir_cache):
101
+ logging.info('Cache %s does not exist.', src_dir_cache)
102
+ return False
103
+ logging.info('Copying %s from cache to %s.', src_dir_cache, dst_directory)
104
+ shutil.copytree(src_dir_cache, dst_directory, dirs_exist_ok=True)
105
+ return True
106
+
107
+ def download_corpus(self, name, dst_directory):
108
+ """GitLab artifacts implementation of download_corpus."""
109
+ # Use the git filestore if any.
110
+ if self.git_filestore:
111
+ self.git_filestore.download_corpus(name, dst_directory)
112
+ return
113
+ # Fall back to cache.
114
+ src_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
115
+ self.CORPUS_PREFIX + name)
116
+ self._copy_from_cache(src_dir_cache, dst_directory)
117
+
118
+ def download_build(self, name, dst_directory):
119
+ """GitLab artifacts implementation of download_build."""
120
+ # Gets build from the cache.
121
+ src_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
122
+ self.BUILD_PREFIX + name)
123
+ return self._copy_from_cache(src_dir_cache, dst_directory)
124
+
125
+ def download_coverage(self, name, dst_directory):
126
+ """GitLab artifacts implementation of download_coverage."""
127
+ # Use the git filestore if any.
128
+ if self.git_filestore:
129
+ return self.git_filestore.download_coverage(name, dst_directory)
130
+ # Fall back to cache.
131
+ src_dir_cache = os.path.join(self.config.project_src_path, self.cache_dir,
132
+ self.COVERAGE_PREFIX + name)
133
+ return self._copy_from_cache(src_dir_cache, dst_directory)
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/gsutil/__init__.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Filestore implementation using gsutil."""
15
+ import logging
16
+ import os
17
+ import posixpath
18
+ import subprocess
19
+ import sys
20
+
21
+ # pylint: disable=wrong-import-position,import-error
22
+ sys.path.append(
23
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir,
24
+ os.pardir, os.pardir))
25
+ import filestore
26
+ import utils
27
+
28
+
29
+ def _gsutil_execute(*args, parallel=True):
30
+ """Executes a gsutil command, passing |*args| to gsutil and returns the
31
+ stdout, stderr and returncode. Exceptions on failure."""
32
+ command = ['gsutil']
33
+ if parallel:
34
+ command.append('-m')
35
+ command += list(args)
36
+ logging.info('Executing gsutil command: %s', command)
37
+ return utils.execute(command, check_result=True)
38
+
39
+
40
+ def _rsync(src, dst, recursive=True, delete=False):
41
+ """Executes gsutil rsync on |src| and |dst|"""
42
+ args = ['rsync']
43
+ if recursive:
44
+ args.append('-r')
45
+ if delete:
46
+ args.append('-d')
47
+ args += [src, dst]
48
+ return _gsutil_execute(*args)
49
+
50
+
51
+ class GSUtilFilestore(filestore.BaseFilestore):
52
+ """Filestore implementation using gsutil."""
53
+ BUILD_DIR = 'build'
54
+ CRASHES_DIR = 'crashes'
55
+ CORPUS_DIR = 'corpus'
56
+ COVERAGE_DIR = 'coverage'
57
+
58
+ def __init__(self, config):
59
+ super().__init__(config)
60
+ self._cloud_bucket = self.config.cloud_bucket
61
+
62
+ def _get_gsutil_url(self, name, prefix_dir):
63
+ """Returns the gsutil URL for |name| and |prefix_dir|."""
64
+ if not prefix_dir:
65
+ return posixpath.join(self._cloud_bucket, name)
66
+ return posixpath.join(self._cloud_bucket, prefix_dir, name)
67
+
68
+ def _upload_directory(self, name, directory, prefix, delete=False):
69
+ gsutil_url = self._get_gsutil_url(name, prefix)
70
+ return _rsync(directory, gsutil_url, delete=delete)
71
+
72
+ def _download_directory(self, name, dst_directory, prefix):
73
+ gsutil_url = self._get_gsutil_url(name, prefix)
74
+ return _rsync(gsutil_url, dst_directory)
75
+
76
+ def upload_crashes(self, name, directory):
77
+ """Uploads the crashes at |directory| to |name|."""
78
+ # Name is going to be "current". I don't know if this makes sense outside of
79
+ # GitHub Actions.
80
+ gsutil_url = self._get_gsutil_url(name, self.CRASHES_DIR)
81
+ logging.info('Uploading crashes to %s.', gsutil_url)
82
+ return _rsync(directory, gsutil_url)
83
+
84
+ def upload_corpus(self, name, directory, replace=False):
85
+ """Uploads the crashes at |directory| to |name|."""
86
+ return self._upload_directory(name,
87
+ directory,
88
+ self.CORPUS_DIR,
89
+ delete=replace)
90
+
91
+ def upload_build(self, name, directory):
92
+ """Uploads the build located at |directory| to |name|."""
93
+ return self._upload_directory(name, directory, self.BUILD_DIR)
94
+
95
+ def upload_coverage(self, name, directory):
96
+ """Uploads the coverage report at |directory| to |name|."""
97
+ return self._upload_directory(name, directory, self.COVERAGE_DIR)
98
+
99
+ def download_corpus(self, name, dst_directory):
100
+ """Downloads the corpus located at |name| to |dst_directory|."""
101
+ return self._download_directory(name, dst_directory, self.CORPUS_DIR)
102
+
103
+ def download_build(self, name, dst_directory):
104
+ """Downloads the build with |name| to |dst_directory|."""
105
+ return self._download_directory(name, dst_directory, self.BUILD_DIR)
106
+
107
+ def download_coverage(self, name, dst_directory):
108
+ """Downloads the latest project coverage report."""
109
+ return self._download_directory(name, dst_directory, self.COVERAGE_DIR)
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore/no_filestore/__init__.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Empty filestore implementation for platforms that haven't implemented it."""
15
+ import logging
16
+
17
+ import filestore
18
+
19
+ # pylint:disable=no-self-use,unused-argument
20
+
21
+
22
+ class NoFilestore(filestore.BaseFilestore):
23
+ """Empty Filestore implementation."""
24
+
25
+ def upload_crashes(self, name, directory):
26
+ """Noop implementation of upload_crashes."""
27
+ logging.info('Not uploading crashes because no Filestore.')
28
+
29
+ def upload_corpus(self, name, directory, replace=False):
30
+ """Noop implementation of upload_corpus."""
31
+ logging.info('Not uploading corpus because no Filestore.')
32
+
33
+ def upload_build(self, name, directory):
34
+ """Noop implementation of upload_build."""
35
+ logging.info('Not uploading build because no Filestore.')
36
+
37
+ def upload_coverage(self, name, directory):
38
+ """Noop implementation of upload_coverage."""
39
+ logging.info('Not uploading coverage because no Filestore.')
40
+
41
+ def download_corpus(self, name, dst_directory):
42
+ """Noop implementation of download_corpus."""
43
+ logging.info('Not downloading corpus because no Filestore.')
44
+
45
+ def download_build(self, name, dst_directory):
46
+ """Noop implementation of download_build."""
47
+ logging.info('Not downloading build because no Filestore.')
48
+
49
+ def download_coverage(self, name, dst_directory):
50
+ """Noop implementation of download_coverage."""
51
+ logging.info('Not downloading coverage because no Filestore.')
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/platform_config/prow.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
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
+ """Module for getting the configuration CIFuzz needs to run on prow."""
15
+ import logging
16
+ import os
17
+
18
+ import platform_config
19
+
20
+ # pylint: disable=too-few-public-methods
21
+
22
+
23
+ class PlatformConfig(platform_config.BasePlatformConfig):
24
+ """CI environment for Prow."""
25
+
26
+ @property
27
+ def project_src_path(self):
28
+ """Returns the manually checked out path of the project's source if
29
+ specified or the current directory if not. Prow will run ClusterfuzzLite
30
+ at the directory head for the repo."""
31
+ project_src_path = os.getenv('PROJECT_SRC_PATH', os.getcwd())
32
+ logging.debug('PROJECT_SRC_PATH: %s.', project_src_path)
33
+ return project_src_path
34
+
35
+ @property
36
+ def workspace(self):
37
+ """Returns the workspace."""
38
+ # Let Prow user override workspace, but default to using artifacts dir
39
+ return os.getenv('WORKSPACE', os.getenv('ARTIFACTS'))
40
+
41
+ @property
42
+ def base_ref(self):
43
+ """Returns the base branch to diff against (pr fuzzing)."""
44
+ return os.getenv('PULL_BASE_REF')
45
+
46
+ @property
47
+ def project_repo_name(self):
48
+ """Returns the project repo name."""
49
+ return os.getenv('REPO_NAME')
50
+
51
+ @property
52
+ def base_commit(self):
53
+ """Returns the base commit to diff against (commit fuzzing)."""
54
+ return os.getenv('PULL_BASE_SHA')
55
+
56
+ @property
57
+ def docker_in_docker(self):
58
+ """Returns True if using Docker in Docker."""
59
+ return True
60
+
61
+ @property
62
+ def filestore(self):
63
+ """Returns the filestore used to store persistent data."""
64
+ return os.environ.get('FILESTORE', 'gsutil')
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/.clusterfuzzlite/build.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -eu
2
+ # Copyright 2020 Google Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+
18
+ make clean # Not strictly necessary, since we are building in a fresh dir.
19
+ make -j$(nproc) all # Build the fuzz targets.
20
+
21
+ # Copy the fuzzer executables, zip-ed corpora, option and dictionary files to $OUT
22
+ find . -name '*_fuzzer' -exec cp -v '{}' $OUT ';'
23
+ find . -name '*_fuzzer.dict' -exec cp -v '{}' $OUT ';' # If you have dictionaries.
24
+ find . -name '*_fuzzer.options' -exec cp -v '{}' $OUT ';' # If you have custom options.
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/do_stuff_fuzzer.cpp ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 Google LLC
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
+ #include "my_api.h"
15
+
16
+ #include <string>
17
+
18
+ // Simple fuzz target for DoStuff().
19
+ // See https://llvm.org/docs/LibFuzzer.html for details.
20
+ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
21
+ std::string str(reinterpret_cast<const char *>(data), size);
22
+ DoStuff(str); // Disregard the output.
23
+ return 0;
24
+ }
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/my_api.cpp ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 Google LLC
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
+ // Implementation of "my_api".
16
+ #include "my_api.h"
17
+
18
+ #include <vector>
19
+
20
+ // Do some computations with 'str', return the result.
21
+ // This function contains a bug. Can you spot it?
22
+ size_t DoStuff(const std::string &str) {
23
+ std::vector<int> Vec({0, 1, 2, 3, 4});
24
+ size_t Idx = 0;
25
+ if (str.size() > 5)
26
+ Idx++;
27
+ if (str.find("foo") != std::string::npos)
28
+ Idx++;
29
+ if (str.find("bar") != std::string::npos)
30
+ Idx++;
31
+ if (str.find("ouch") != std::string::npos)
32
+ Idx++;
33
+ if (str.find("omg") != std::string::npos)
34
+ Idx++;
35
+ return Vec[Idx];
36
+ }
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/my_api.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 Google LLC
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
+ // A library that does ... stuff.
16
+ // Serves as an example of good fuzz testing and OSS-Fuzz integration.
17
+ #include <string>
18
+
19
+ size_t DoStuff(const std::string &str);
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/external-project/standalone_fuzz_target_runner.cpp ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 Google LLC
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
+ // Example of a standalone runner for "fuzz targets".
16
+ // It reads all files passed as parameters and feeds their contents
17
+ // one by one into the fuzz target (LLVMFuzzerTestOneInput).
18
+ // This runner does not do any fuzzing, but allows us to run the fuzz target
19
+ // on the test corpus (e.g. "do_stuff_test_data") or on a single file,
20
+ // e.g. the one that comes from a bug report.
21
+
22
+ #include <cassert>
23
+ #include <iostream>
24
+ #include <fstream>
25
+ #include <vector>
26
+
27
+ // Forward declare the "fuzz target" interface.
28
+ // We deliberately keep this inteface simple and header-free.
29
+ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
30
+
31
+ int main(int argc, char **argv) {
32
+ for (int i = 1; i < argc; i++) {
33
+ std::ifstream in(argv[i]);
34
+ in.seekg(0, in.end);
35
+ size_t length = in.tellg();
36
+ in.seekg (0, in.beg);
37
+ std::cout << "Reading " << length << " bytes from " << argv[i] << std::endl;
38
+ // Allocate exactly length bytes so that we reliably catch buffer overflows.
39
+ std::vector<char> bytes(length);
40
+ in.read(bytes.data(), bytes.size());
41
+ assert(in);
42
+ LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()),
43
+ bytes.size());
44
+ std::cout << "Execution successful" << std::endl;
45
+ }
46
+ return 0;
47
+ }
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/cifuzz/test_data/msan_crash_fuzzer_output.txt ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Dictionary: 3 entries
2
+ INFO: Running with entropic power schedule (0xFF, 100).
3
+ INFO: Seed: 1337
4
+ INFO: Loaded 1 modules (184 inline 8-bit counters): 184 [0x829300, 0x8293b8),
5
+ INFO: Loaded 1 PC tables (184 PCs): 184 [0x5dc910,0x5dd490),
6
+ INFO: 5 files found in /tmp/do_stuff_fuzzer_corpus
7
+ INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
8
+ ==13==WARNING: MemorySanitizer: use-of-uninitialized-value
9
+ #0 0x52675f in LLVMFuzzerTestOneInput /src/cifuzz-example/do_stuff_fuzzer.cpp:13:7
10
+ #1 0x45a431 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:599:15
11
+ #2 0x45ba46 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:792:3
12
+ #3 0x45bed9 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:845:3
13
+ #4 0x44a4bc in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:906:6
14
+ #5 0x474432 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
15
+ #6 0x7eff5562683f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
16
+ #7 0x41eab8 in _start (out/do_stuff_fuzzer+0x41eab8)
17
+
18
+ DEDUP_TOKEN: LLVMFuzzerTestOneInput--fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long)--fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&)
19
+ Uninitialized value was created by a heap allocation
20
+ #0 0x4d57ad in malloc /src/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:901:3
21
+ #1 0x437c07 in operator new(unsigned long) (out/do_stuff_fuzzer+0x437c07)
22
+ #2 0x45ba46 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:792:3
23
+ #3 0x45bed9 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:845:3
24
+ #4 0x44a4bc in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:906:6
25
+ #5 0x474432 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
26
+ #6 0x7eff5562683f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
27
+ DEDUP_TOKEN: malloc--operator new(unsigned long)--fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&)
28
+
29
+ SUMMARY: MemorySanitizer: use-of-uninitialized-value /src/cifuzz-example/do_stuff_fuzzer.cpp:13:7 in LLVMFuzzerTestOneInput
30
+ Unique heap origins: 65
31
+ Stack depot allocated bytes: 4424
32
+ Unique origin histories: 29
33
+ History depot allocated bytes: 696
34
+ Exiting
35
+ MS: 0 ; base unit: 0000000000000000000000000000000000000000
36
+
37
+
38
+ artifact_prefix='./'; Test unit written to ./crash-da39a3ee5e6b4b0d3255bfef95601890afd80709
39
+ Base64:
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ wycheproof.zip
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/generate_job.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+ """Script for generating an OSS-Fuzz job for a wycheproof project."""
18
+ import sys
19
+
20
+
21
+ def main():
22
+ """Usage generate_job.py <project>."""
23
+ project = sys.argv[1]
24
+ print(f'Name: wycheproof_nosanitizer_{project}')
25
+ job_definition = f"""CUSTOM_BINARY = False
26
+ BAD_BUILD_CHECK = False
27
+ APP_NAME = WycheproofTarget.bash
28
+ THREAD_ALIVE_CHECK_INTERVAL = 10
29
+ TEST_TIMEOUT = 3600
30
+ CRASH_RETRIES = 1
31
+ AGGREGATE_COVERAGE = False
32
+ TESTCASE_COVERAGE = False
33
+ FILE_GITHUB_ISSUE = False
34
+ MANAGED = False
35
+ MAX_FUZZ_THREADS = 1
36
+ RELEASE_BUILD_BUCKET_PATH = gs://clusterfuzz-builds-wycheproof/{project}/{project}-none-([0-9]+).zip
37
+ PROJECT_NAME = {project}
38
+ SUMMARY_PREFIX = {project}
39
+ REVISION_VARS_URL = https://commondatastorage.googleapis.com/clusterfuzz-builds-wycheproof/{project}/{project}-none-%s.srcmap.json
40
+ FUZZ_LOGS_BUCKET = {project}-logs.clusterfuzz-external.appspot.com
41
+ CORPUS_BUCKET = {project}-corpus.clusterfuzz-external.appspot.com
42
+ QUARANTINE_BUCKET = {project}-quarantine.clusterfuzz-external.appspot.com
43
+ BACKUP_BUCKET = {project}-backup.clusterfuzz-external.appspot.com
44
+ AUTOMATIC_LABELS = Proj-{project},Engine-wycheproof
45
+ """
46
+ print(job_definition)
47
+
48
+
49
+ if __name__ == '__main__':
50
+ main()
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/launcher.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+ """Script for running wycheproof."""
18
+
19
+ import logging
20
+ import sys
21
+ import subprocess
22
+
23
+
24
+ def main():
25
+ """Runs wycheproof."""
26
+ if len(sys.argv) < 3:
27
+ logging.error('Usage: %s <test_app> <testcase>.', sys.argv[0])
28
+ return 1
29
+
30
+ return subprocess.run(sys.argv[1:], check=False).returncode
31
+
32
+
33
+ if __name__ == '__main__':
34
+ sys.exit(main())
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/tools/wycheproof/run.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+ """Script for creating "testcases" to run wycheproof on."""
18
+
19
+ import argparse
20
+ import os
21
+ import sys
22
+
23
+
24
+ def get_args():
25
+ """Returns parsed program arguments."""
26
+ parser = argparse.ArgumentParser()
27
+ parser.add_argument(
28
+ '--input_dir',
29
+ help='Ignored.',
30
+ )
31
+ parser.add_argument('--output_dir',
32
+ help='Directory for writing testcases.',
33
+ required=True)
34
+ parser.add_argument('--no_of_files', type=int, help='Ignored.')
35
+ return parser.parse_args()
36
+
37
+
38
+ def main():
39
+ """Generates a dummy testcase for use by a ClusterFuzz blackbox fuzzer."""
40
+ args = get_args()
41
+ if not os.path.exists(args.output_dir):
42
+ os.mkdir(args.output_dir)
43
+ testcase = os.path.join(args.output_dir, 'fuzz-0')
44
+ with open(testcase, 'w') as file_handle:
45
+ file_handle.write(' ')
46
+ return 0
47
+
48
+
49
+ if __name__ == '__main__':
50
+ sys.exit(main())