Kitxuuu commited on
Commit
2d71ed6
·
verified ·
1 Parent(s): 6951d20

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-fuzzbench/fuzzbench_measure +32 -0
  2. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-fuzzbench/fuzzbench_run_fuzzer +41 -0
  3. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-go/Dockerfile +33 -0
  4. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-go/gosigfuzz.c +47 -0
  5. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner-debug/Dockerfile +26 -0
  6. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/coverage_helper +17 -0
  7. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/download_corpus +30 -0
  8. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/generate_differential_cov_report.py +228 -0
  9. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/install_go.sh +41 -0
  10. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/jacoco_report_converter.py +174 -0
  11. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/reproduce +34 -0
  12. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/ruzzy +19 -0
  13. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/cifuzz/actions/run_fuzzers/action.yml +82 -0
  14. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/cifuzz/filestore/git/git_test.py +122 -0
  15. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/cifuzz/filestore/gitlab/__init__.py +133 -0
  16. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/cifuzz/filestore/gsutil/__init__.py +109 -0
  17. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/tools/wycheproof/.gitignore +1 -0
  18. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/tools/wycheproof/launcher.py +34 -0
  19. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/tools/wycheproof/package.bash +18 -0
  20. local-test-tika-full-01-vuln_0/fuzz-tooling/infra/tools/wycheproof/run.py +50 -0
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-fuzzbench/fuzzbench_measure ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash -eux
2
+ # Copyright 2023 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
+
18
+ # TODO(metzman): Make these configurable.
19
+ export DB_PATH=$OUT/experiment.db
20
+ export SNAPSHOT_PERIOD=30
21
+ export EXPERIMENT_FILESTORE=$OUT/filestore
22
+ export MAX_TOTAL_TIME=120
23
+ export EXPERIMENT=oss-fuzz-on-demand
24
+
25
+ rm -f $DB_PATH
26
+
27
+ # FUZZER=mopt BENCHMARK=skcms
28
+
29
+ export SQL_DATABASE_URL=sqlite:///$DB_PATH
30
+
31
+ cd $FUZZBENCH_PATH
32
+ PYTHONPATH=. python3 -B experiment/measurer/standalone.py $MAX_TOTAL_TIME
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-fuzzbench/fuzzbench_run_fuzzer ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash -eux
2
+ # Copyright 2023 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
+
18
+ export RUNNER_NICENESS="-5"
19
+ export EXPERIMENT_FILESTORE=$OUT/filestore
20
+ export EXPERIMENT=oss-fuzz-on-demand
21
+ export OSS_FUZZ_ON_DEMAND=1
22
+ export OUTPUT_CORPUS_DIR=/output-corpus
23
+ export SEED_CORPUS_DIR=/input-corpus
24
+ mkdir $SEED_CORPUS_DIR
25
+ rm -rf $OUTPUT_CORPUS_DIR
26
+ mkdir $OUTPUT_CORPUS_DIR
27
+ export FUZZER=$FUZZING_ENGINE
28
+ # TODO(metzman): Make this configurable.
29
+ export MAX_TOTAL_TIME=120
30
+ export SNAPSHOT_PERIOD=30
31
+ export TRIAL_ID=1
32
+ export FORCE_LOCAL=1
33
+
34
+ # BENCHMARK, FUZZ_TARGET
35
+ cd $OUT
36
+
37
+ # Prevent permissions issues with pyc files and docker.
38
+ cp -r $FUZZBENCH_PATH /tmp/fuzzbench
39
+
40
+ PYTHONPATH=/tmp/fuzzbench nice -n $RUNNER_NICENESS python3 -B -u /tmp/fuzzbench/experiment/runner.py
41
+ cat $EXPERIMENT_FILESTORE/$EXPERIMENT/experiment-folders/$BENCHMARK-$FUZZER/trial-$TRIAL_ID/results/fuzzer-log.txt
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-go/Dockerfile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #
15
+ ################################################################################
16
+
17
+ ARG IMG_TAG=latest
18
+ FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG}
19
+
20
+ # Set up Golang environment variables (copied from /root/.bash_profile).
21
+ ENV GOPATH /root/go
22
+
23
+ # /root/.go/bin is for the standard Go binaries (i.e. go, gofmt, etc).
24
+ # $GOPATH/bin is for the binaries from the dependencies installed via "go get".
25
+ ENV PATH $PATH:/root/.go/bin:$GOPATH/bin
26
+
27
+ COPY gosigfuzz.c $GOPATH/gosigfuzz/
28
+
29
+ RUN install_go.sh
30
+
31
+ # TODO(jonathanmetzman): Install this file using install_go.sh.
32
+ COPY ossfuzz_coverage_runner.go \
33
+ $GOPATH/
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-builder-go/gosigfuzz.c ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2023 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
+ #include<stdlib.h>
18
+ #include<signal.h>
19
+
20
+ static void fixSignalHandler(int signum) {
21
+ struct sigaction new_action;
22
+ struct sigaction old_action;
23
+ sigemptyset (&new_action.sa_mask);
24
+ sigaction (signum, NULL, &old_action);
25
+ new_action.sa_flags = old_action.sa_flags | SA_ONSTACK;
26
+ new_action.sa_sigaction = old_action.sa_sigaction;
27
+ new_action.sa_handler = old_action.sa_handler;
28
+ sigaction (signum, &new_action, NULL);
29
+ }
30
+
31
+ static void FixStackSignalHandler() {
32
+ fixSignalHandler(SIGSEGV);
33
+ fixSignalHandler(SIGABRT);
34
+ fixSignalHandler(SIGALRM);
35
+ fixSignalHandler(SIGINT);
36
+ fixSignalHandler(SIGTERM);
37
+ fixSignalHandler(SIGBUS);
38
+ fixSignalHandler(SIGFPE);
39
+ fixSignalHandler(SIGXFSZ);
40
+ fixSignalHandler(SIGUSR1);
41
+ fixSignalHandler(SIGUSR2);
42
+ }
43
+
44
+ int LLVMFuzzerInitialize(int *argc, char ***argv) {
45
+ FixStackSignalHandler();
46
+ return 0;
47
+ }
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner-debug/Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2016 Google Inc.
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
+
17
+ ARG IMG_TAG=latest
18
+ FROM ghcr.io/aixcc-finals/base-runner:${IMG_TAG}
19
+ RUN apt-get update && apt-get install -y valgrind zip
20
+
21
+ # Installing GDB 12, re https://github.com/google/oss-fuzz/issues/7513.
22
+ RUN apt-get install -y build-essential libgmp-dev && \
23
+ wget https://ftp.gnu.org/gnu/gdb/gdb-12.1.tar.xz && \
24
+ tar -xf gdb-12.1.tar.xz && cd gdb-12.1 && ./configure && \
25
+ make -j $(expr $(nproc) / 2) && make install && cd .. && \
26
+ rm -rf gdb-12.1* && apt-get remove --purge -y build-essential libgmp-dev
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/coverage_helper ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -u
2
+ # Copyright 2018 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
+ python3 $CODE_COVERAGE_SRC/coverage_utils.py $@
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/download_corpus ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -u
2
+ # Copyright 2018 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
+ if (( $# < 1 )); then
19
+ echo "Usage: $0 \"path_download_to url_download_from\" (can be repeated)" >&2
20
+ exit 1
21
+ fi
22
+
23
+ for pair in "$@"; do
24
+ read path url <<< "$pair"
25
+ wget -q -O $path $url
26
+ done
27
+
28
+ # Always exit with 0 as we do not track wget return codes and should not rely
29
+ # on the latest command execution.
30
+ exit 0
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/generate_differential_cov_report.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ #
3
+ # Copyright 2023 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ ################################################################################
18
+ """Script for generating differential coverage reports.
19
+ generate_differential_cov_report.py <profdata-dump-directory> \
20
+ <profdata-directory-to-subtract-from-first> <output-directory>
21
+ """
22
+ import os
23
+ import shutil
24
+ import subprocess
25
+ import sys
26
+
27
+
28
+ class ProfData:
29
+ """Class representing a profdata file."""
30
+
31
+ def __init__(self, text):
32
+ self.function_profs = []
33
+ for function_prof in text.split('\n\n'):
34
+ if not function_prof:
35
+ continue
36
+ self.function_profs.append(FunctionProf(function_prof))
37
+
38
+ def to_string(self):
39
+ """Convert back to a string."""
40
+ return '\n'.join(
41
+ [function_prof.to_string() for function_prof in self.function_profs])
42
+
43
+ def find_function(self, function, idx=None):
44
+ """Find the same function in this profdata."""
45
+ if idx is not None:
46
+ try:
47
+ possibility = self.function_profs[idx]
48
+ if function.func_hash == possibility.func_hash:
49
+ return possibility
50
+ except IndexError:
51
+ pass
52
+ for function_prof in self.function_profs:
53
+ if function_prof.func_hash == function.func_hash:
54
+ return function_prof
55
+ return None
56
+
57
+ def subtract(self, subtrahend):
58
+ """Subtract subtrahend from this profdata."""
59
+ for idx, function_prof in enumerate(self.function_profs):
60
+ subtrahend_function_prof = subtrahend.find_function(function_prof, idx)
61
+ function_prof.subtract(subtrahend_function_prof)
62
+
63
+
64
+ class FunctionProf:
65
+ """Profile of a function."""
66
+ FUNC_HASH_COMMENT_LINE = '# Func Hash:'
67
+ NUM_COUNTERS_COMMENT_LINE = '# Num Counters:'
68
+ COUNTER_VALUES_COMMENT_LINE = '# Counter Values:'
69
+
70
+ def __init__(self, text):
71
+ print(text)
72
+ lines = text.splitlines()
73
+ self.function = lines[0]
74
+ assert self.FUNC_HASH_COMMENT_LINE == lines[1]
75
+ self.func_hash = lines[2]
76
+ assert self.NUM_COUNTERS_COMMENT_LINE == lines[3]
77
+ self.num_counters = int(lines[4])
78
+ assert self.COUNTER_VALUES_COMMENT_LINE == lines[5]
79
+ self.counter_values = [1 if int(line) else 0 for line in lines[6:]]
80
+
81
+ def to_string(self):
82
+ """Convert back to text."""
83
+ lines = [
84
+ self.function,
85
+ self.FUNC_HASH_COMMENT_LINE,
86
+ self.func_hash,
87
+ self.NUM_COUNTERS_COMMENT_LINE,
88
+ str(self.num_counters),
89
+ self.COUNTER_VALUES_COMMENT_LINE,
90
+ ] + [str(num) for num in self.counter_values]
91
+ return '\n'.join(lines)
92
+
93
+ def subtract(self, subtrahend_prof):
94
+ """Subtract this other function from this function."""
95
+ if not subtrahend_prof:
96
+ print(self.function, 'has no subtrahend')
97
+ # Nothing to subtract.
98
+ return
99
+ self.counter_values = [
100
+ max(counter1 - counter2, 0) for counter1, counter2 in zip(
101
+ self.counter_values, subtrahend_prof.counter_values)
102
+ ]
103
+
104
+
105
+ def get_profdata_files(directory):
106
+ """Returns profdata files in |directory|."""
107
+ profdatas = []
108
+ for filename in os.listdir(directory):
109
+ filename = os.path.join(directory, filename)
110
+ if filename.endswith('.profdata'):
111
+ profdatas.append(filename)
112
+ return profdatas
113
+
114
+
115
+ def convert_profdata_to_text(profdata):
116
+ """Convert a profdata binary file to a profdata text file."""
117
+ profdata_text = f'{profdata}.txt'
118
+ if os.path.exists(profdata_text):
119
+ os.remove(profdata_text)
120
+ command = [
121
+ 'llvm-profdata', 'merge', '-j=1', '-sparse', profdata, '--text', '-o',
122
+ profdata_text
123
+ ]
124
+ print(command)
125
+ subprocess.run(command, check=True)
126
+ return profdata_text
127
+
128
+
129
+ def convert_text_profdata_to_bin(profdata_text):
130
+ """Convert a profdata text file to a profdata binary file."""
131
+ profdata = profdata_text.replace('.txt', '').replace('.profdata',
132
+ '') + '.profdata'
133
+ print('bin profdata', profdata)
134
+ if os.path.exists(profdata):
135
+ os.remove(profdata)
136
+ command = [
137
+ 'llvm-profdata', 'merge', '-j=1', '-sparse', profdata_text, '-o', profdata
138
+ ]
139
+ print(command)
140
+ subprocess.run(command, check=True)
141
+ return profdata
142
+
143
+
144
+ def get_difference(minuend_filename, subtrahend_filename):
145
+ """Subtract subtrahend_filename from minuend_filename."""
146
+ with open(minuend_filename, 'r', encoding='utf-8') as minuend_file:
147
+ print('minuend', minuend_filename)
148
+ minuend = ProfData(minuend_file.read())
149
+ with open(subtrahend_filename, 'r', encoding='utf-8') as subtrahend_file:
150
+ print('subtrahend', subtrahend_filename)
151
+ subtrahend = ProfData(subtrahend_file.read())
152
+
153
+ minuend.subtract(subtrahend)
154
+ return minuend
155
+
156
+
157
+ def profdatas_to_objects(profdatas):
158
+ """Get the corresponding objects for each profdata."""
159
+ return [
160
+ os.path.splitext(os.path.basename(profdata))[0] for profdata in profdatas
161
+ ]
162
+
163
+
164
+ def generate_differential_cov_reports(minuend_profdatas, subtrahend_profdatas,
165
+ difference_dir):
166
+ """Calculate the differences between all profdatas and generate differential
167
+ coverage reports."""
168
+ profdata_objects = profdatas_to_objects(minuend_profdatas)
169
+ real_profdata_objects = [
170
+ binobject for binobject in profdata_objects if binobject != 'merged'
171
+ ]
172
+ for minuend, subtrahend, binobject in zip(minuend_profdatas,
173
+ subtrahend_profdatas,
174
+ profdata_objects):
175
+ minuend_text = convert_profdata_to_text(minuend)
176
+ subtrahend_text = convert_profdata_to_text(subtrahend)
177
+ difference = get_difference(minuend_text, subtrahend_text)
178
+ basename = os.path.basename(minuend_text)
179
+ difference_text = os.path.join(difference_dir, basename)
180
+ with open(difference_text, 'w', encoding='utf-8') as file_handle:
181
+ file_handle.write(difference.to_string())
182
+ difference_profdata = convert_text_profdata_to_bin(difference_text)
183
+ if not difference_profdata.endswith('merged.profdata'):
184
+ generate_html_report(difference_profdata, [binobject],
185
+ os.path.join(difference_dir, binobject))
186
+ else:
187
+ generate_html_report(difference_profdata, real_profdata_objects,
188
+ os.path.join(difference_dir, 'merged'))
189
+
190
+
191
+ def generate_html_report(profdata, objects, directory):
192
+ """Generate an HTML coverage report."""
193
+ # TODO(metzman): Deal with shared libs.
194
+ html_dir = os.path.join(directory, 'reports')
195
+ if os.path.exists(html_dir):
196
+ os.remove(html_dir)
197
+ os.makedirs(html_dir)
198
+ out_dir = os.getenv('OUT', '/out')
199
+ command = [
200
+ 'llvm-cov', 'show', f'-path-equivalence=/,{out_dir}', '-format=html',
201
+ '-Xdemangler', 'rcfilt', f'-instr-profile={profdata}'
202
+ ]
203
+
204
+ objects = [os.path.join(out_dir, binobject) for binobject in objects]
205
+ command += objects + ['-o', html_dir]
206
+ print(' '.join(command))
207
+ subprocess.run(command, check=True)
208
+
209
+
210
+ def main():
211
+ """Generate differential coverage reports."""
212
+ if len(sys.argv) != 4:
213
+ print(
214
+ f'Usage: {sys.argv[0]} <minuend_dir> <subtrahend_dir> <difference_dir>')
215
+ minuend_dir = sys.argv[1]
216
+ subtrahend_dir = sys.argv[2]
217
+ difference_dir = sys.argv[3]
218
+ if os.path.exists(difference_dir):
219
+ shutil.rmtree(difference_dir)
220
+ os.makedirs(difference_dir, exist_ok=True)
221
+ minuend_profdatas = get_profdata_files(minuend_dir)
222
+ subtrahend_profdatas = get_profdata_files(subtrahend_dir)
223
+ generate_differential_cov_reports(minuend_profdatas, subtrahend_profdatas,
224
+ difference_dir)
225
+
226
+
227
+ if __name__ == '__main__':
228
+ main()
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/install_go.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -eux
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
+
18
+ # Install go on x86_64, don't do anything on ARM.
19
+
20
+ case $(uname -m) in
21
+ x86_64)
22
+ # Download and install Go 1.19.
23
+ wget -q https://storage.googleapis.com/golang/getgo/installer_linux -O $SRC/installer_linux
24
+ chmod +x $SRC/installer_linux
25
+ SHELL="bash" $SRC/installer_linux -version 1.19
26
+ rm $SRC/installer_linux
27
+ # Set up Golang coverage modules.
28
+ printf $(find . -name gocoverage)
29
+ cd $GOPATH/gocoverage && /root/.go/bin/go install ./...
30
+ cd convertcorpus && /root/.go/bin/go install .
31
+ cd /root/.go/src/cmd/cover && /root/.go/bin/go build && mv cover $GOPATH/bin/gotoolcover
32
+ ;;
33
+ aarch64)
34
+ # Don't install go because installer is not provided.
35
+ echo "Not installing go: aarch64."
36
+ ;;
37
+ *)
38
+ echo "Error: unsupported architecture: $(uname -m)"
39
+ exit 1
40
+ ;;
41
+ esac
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/jacoco_report_converter.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
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
+ #
16
+ ################################################################################
17
+ """Helper script for creating an llvm-cov style JSON summary from a JaCoCo XML
18
+ report."""
19
+ import json
20
+ import os
21
+ import sys
22
+ import xml.etree.ElementTree as ET
23
+
24
+
25
+ def convert(xml):
26
+ """Turns a JaCoCo XML report into an llvm-cov JSON summary."""
27
+ summary = {
28
+ 'type': 'oss-fuzz.java.coverage.json.export',
29
+ 'version': '1.0.0',
30
+ 'data': [{
31
+ 'totals': {},
32
+ 'files': [],
33
+ }],
34
+ }
35
+
36
+ report = ET.fromstring(xml)
37
+ totals = make_element_summary(report)
38
+ summary['data'][0]['totals'] = totals
39
+
40
+ # Since Java compilation does not track source file location, we match
41
+ # coverage info to source files via the full class name, e.g. we search for
42
+ # a path in /out/src ending in foo/bar/Baz.java for the class foo.bar.Baz.
43
+ # Under the assumptions that a given project only ever contains a single
44
+ # version of a class and that no class name appears as a suffix of another
45
+ # class name, we can assign coverage info to every source file matched in that
46
+ # way.
47
+ src_files = list_src_files()
48
+
49
+ for class_element in report.findall('./package/class'):
50
+ # Skip fuzzer classes
51
+ if is_fuzzer_class(class_element):
52
+ continue
53
+
54
+ # Skip non class elements
55
+ if 'sourcefilename' not in class_element.attrib:
56
+ continue
57
+
58
+ class_name = class_element.attrib['name']
59
+ package_name = os.path.dirname(class_name)
60
+ basename = class_element.attrib['sourcefilename']
61
+ # This path is 'foo/Bar.java' for the class element
62
+ # <class name="foo/Bar" sourcefilename="Bar.java">.
63
+ canonical_path = os.path.join(package_name, basename)
64
+
65
+ class_summary = make_element_summary(class_element)
66
+ for src_file in relative_to_src_path(src_files, canonical_path):
67
+ summary['data'][0]['files'].append({
68
+ 'filename': src_file,
69
+ 'summary': class_summary,
70
+ })
71
+
72
+ return json.dumps(summary)
73
+
74
+
75
+ def list_src_files():
76
+ """Returns a map from basename to full path for all files in $OUT/$SRC."""
77
+ filename_to_paths = {}
78
+ out_path = os.environ['OUT'] + '/'
79
+ src_path = os.environ['SRC']
80
+ src_in_out = out_path + src_path
81
+ for dirpath, _, filenames in os.walk(src_in_out):
82
+ for filename in filenames:
83
+ full_path = dirpath + '/' + filename
84
+ # Map /out//src/... to /src/...
85
+ file_path = full_path[len(out_path):]
86
+ filename_to_paths.setdefault(filename, []).append(file_path)
87
+ return filename_to_paths
88
+
89
+
90
+ def is_fuzzer_class(class_element):
91
+ """Check if the class is fuzzer class."""
92
+ method_elements = class_element.find('./method[@name=\"fuzzerTestOneInput\"]')
93
+ if method_elements:
94
+ return True
95
+
96
+ return False
97
+
98
+
99
+ def relative_to_src_path(src_files, canonical_path):
100
+ """Returns all paths in src_files ending in canonical_path."""
101
+ basename = os.path.basename(canonical_path)
102
+ if basename not in src_files:
103
+ return []
104
+ candidate_paths = src_files[basename]
105
+ return [
106
+ path for path in candidate_paths if path.endswith("/" + canonical_path)
107
+ ]
108
+
109
+
110
+ def make_element_summary(element):
111
+ """Returns a coverage summary for an element in the XML report."""
112
+ summary = {}
113
+
114
+ function_counter = element.find('./counter[@type=\'METHOD\']')
115
+ summary['functions'] = make_counter_summary(function_counter)
116
+
117
+ line_counter = element.find('./counter[@type=\'LINE\']')
118
+ summary['lines'] = make_counter_summary(line_counter)
119
+
120
+ # JaCoCo tracks branch coverage, which counts the covered control-flow edges
121
+ # between llvm-cov's regions instead of the covered regions themselves. For
122
+ # non-trivial code parts, the difference is usually negligible. However, if
123
+ # all methods of a class consist of a single region only (no branches),
124
+ # JaCoCo does not report any branch coverage even if there is instruction
125
+ # coverage. Since this would give incorrect results for CI Fuzz purposes, we
126
+ # increase the regions counter by 1 if there is any amount of instruction
127
+ # coverage.
128
+ instruction_counter = element.find('./counter[@type=\'INSTRUCTION\']')
129
+ has_some_coverage = instruction_counter is not None and int(
130
+ instruction_counter.attrib["covered"]) > 0
131
+ branch_covered_adjustment = 1 if has_some_coverage else 0
132
+ region_counter = element.find('./counter[@type=\'BRANCH\']')
133
+ summary['regions'] = make_counter_summary(
134
+ region_counter, covered_adjustment=branch_covered_adjustment)
135
+
136
+ return summary
137
+
138
+
139
+ def make_counter_summary(counter_element, covered_adjustment=0):
140
+ """Turns a JaCoCo <counter> element into an llvm-cov totals entry."""
141
+ summary = {}
142
+ covered = covered_adjustment
143
+ missed = 0
144
+ if counter_element is not None:
145
+ covered += int(counter_element.attrib['covered'])
146
+ missed += int(counter_element.attrib['missed'])
147
+ summary['covered'] = covered
148
+ summary['notcovered'] = missed
149
+ summary['count'] = summary['covered'] + summary['notcovered']
150
+ if summary['count'] != 0:
151
+ summary['percent'] = (100.0 * summary['covered']) / summary['count']
152
+ else:
153
+ summary['percent'] = 0
154
+ return summary
155
+
156
+
157
+ def main():
158
+ """Produces an llvm-cov style JSON summary from a JaCoCo XML report."""
159
+ if len(sys.argv) != 3:
160
+ sys.stderr.write('Usage: %s <path_to_jacoco_xml> <out_path_json>\n' %
161
+ sys.argv[0])
162
+ return 1
163
+
164
+ with open(sys.argv[1], 'r') as xml_file:
165
+ xml_report = xml_file.read()
166
+ json_summary = convert(xml_report)
167
+ with open(sys.argv[2], 'w') as json_file:
168
+ json_file.write(json_summary)
169
+
170
+ return 0
171
+
172
+
173
+ if __name__ == '__main__':
174
+ sys.exit(main())
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/reproduce ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -eux
2
+ # Copyright 2016 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
+ FUZZER=$1
19
+ shift
20
+
21
+ if [ ! -v TESTCASE ]; then
22
+ TESTCASE="/testcase"
23
+ fi
24
+
25
+ if [ ! -f $TESTCASE ]; then
26
+ echo "Error: $TESTCASE not found, use: docker run -v <path>:$TESTCASE ..."
27
+ exit 1
28
+ fi
29
+
30
+ export RUN_FUZZER_MODE="interactive"
31
+ export FUZZING_ENGINE="libfuzzer"
32
+ export SKIP_SEED_CORPUS="1"
33
+
34
+ run_fuzzer $FUZZER $@ $TESTCASE
local-test-tika-full-01-vuln_0/fuzz-tooling/infra/base-images/base-runner/ruzzy ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Copyright 2024 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
+
18
+ ASAN_OPTIONS="allocator_may_return_null=1:detect_leaks=0:use_sigaltstack=0" LD_PRELOAD=$(ruby -e 'require "ruzzy"; print Ruzzy::ASAN_PATH') \
19
+ ruby $@
local-test-tika-full-01-vuln_0/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_0/fuzz-tooling/infra/cifuzz/filestore/git/git_test.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 git."""
15
+ import filecmp
16
+ import os
17
+ import tempfile
18
+ import subprocess
19
+ import sys
20
+ import unittest
21
+ from unittest import mock
22
+
23
+ # pylint: disable=wrong-import-position
24
+ INFRA_DIR = os.path.dirname(
25
+ os.path.dirname(os.path.dirname(os.path.dirname(
26
+ os.path.abspath(__file__)))))
27
+ sys.path.append(INFRA_DIR)
28
+
29
+ from filestore import git
30
+ import test_helpers
31
+
32
+ # pylint: disable=protected-access,no-self-use
33
+
34
+
35
+ class GitFilestoreTest(unittest.TestCase):
36
+ """Tests for GitFilestore."""
37
+
38
+ def setUp(self):
39
+ self.git_dir = tempfile.TemporaryDirectory()
40
+ self.addCleanup(self.git_dir.cleanup)
41
+
42
+ self.local_dir = tempfile.TemporaryDirectory()
43
+ self.addCleanup(self.local_dir.cleanup)
44
+
45
+ self.download_dir = tempfile.TemporaryDirectory()
46
+ self.addCleanup(self.download_dir.cleanup)
47
+
48
+ with open(os.path.join(self.local_dir.name, 'a'), 'w') as handle:
49
+ handle.write('')
50
+
51
+ os.makedirs(os.path.join(self.local_dir.name, 'b'))
52
+
53
+ with open(os.path.join(self.local_dir.name, 'b', 'c'), 'w') as handle:
54
+ handle.write('')
55
+
56
+ self.git_repo = git.git_runner(self.git_dir.name)
57
+ self.git_repo('init', '--bare')
58
+
59
+ self.config = test_helpers.create_run_config(
60
+ git_store_repo='file://' + self.git_dir.name,
61
+ git_store_branch='main',
62
+ git_store_branch_coverage='cov-branch')
63
+
64
+ self.mock_ci_filestore = mock.MagicMock()
65
+ self.git_store = git.GitFilestore(self.config, self.mock_ci_filestore)
66
+
67
+ def assert_dirs_same(self, first, second):
68
+ """Asserts two dirs are the same."""
69
+ dcmp = filecmp.dircmp(first, second)
70
+ if dcmp.diff_files or dcmp.left_only or dcmp.right_only:
71
+ return False
72
+
73
+ return all(
74
+ self.assert_dirs_same(os.path.join(first, subdir),
75
+ os.path.join(second, subdir))
76
+ for subdir in dcmp.common_dirs)
77
+
78
+ def get_repo_filelist(self, branch):
79
+ """Get files in repo."""
80
+ return subprocess.check_output([
81
+ 'git', '-C', self.git_dir.name, 'ls-tree', '-r', '--name-only', branch
82
+ ]).decode().splitlines()
83
+
84
+ def test_upload_download_corpus(self):
85
+ """Tests uploading and downloading corpus."""
86
+ self.git_store.upload_corpus('target', self.local_dir.name)
87
+ self.git_store.download_corpus('target', self.download_dir.name)
88
+ self.assert_dirs_same(self.local_dir.name, self.download_dir.name)
89
+
90
+ self.assertCountEqual([
91
+ 'corpus/target/a',
92
+ 'corpus/target/b/c',
93
+ ], self.get_repo_filelist('main'))
94
+
95
+ def test_upload_download_coverage(self):
96
+ """Tests uploading and downloading corpus."""
97
+ self.git_store.upload_coverage('latest', self.local_dir.name)
98
+ self.git_store.download_coverage('latest', self.download_dir.name)
99
+ self.assert_dirs_same(self.local_dir.name, self.download_dir.name)
100
+
101
+ self.assertCountEqual([
102
+ 'coverage/latest/a',
103
+ 'coverage/latest/b/c',
104
+ ], self.get_repo_filelist('cov-branch'))
105
+
106
+ def test_upload_crashes(self):
107
+ """Tests uploading crashes."""
108
+ self.git_store.upload_crashes('current', self.local_dir.name)
109
+ self.mock_ci_filestore.upload_crashes.assert_called_with(
110
+ 'current', self.local_dir.name)
111
+
112
+ def test_upload_build(self):
113
+ """Tests uploading build."""
114
+ self.git_store.upload_build('sanitizer', self.local_dir.name)
115
+ self.mock_ci_filestore.upload_build.assert_called_with(
116
+ 'sanitizer', self.local_dir.name)
117
+
118
+ def test_download_build(self):
119
+ """Tests downloading build."""
120
+ self.git_store.download_build('sanitizer', self.download_dir.name)
121
+ self.mock_ci_filestore.download_build.assert_called_with(
122
+ 'sanitizer', self.download_dir.name)
local-test-tika-full-01-vuln_0/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_0/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_0/fuzz-tooling/infra/tools/wycheproof/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ wycheproof.zip
local-test-tika-full-01-vuln_0/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_0/fuzz-tooling/infra/tools/wycheproof/package.bash ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
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 zipping ClusterFuzz's blackbox fuzzer for wycheproof.
18
+ zip wycheproof.zip run.py launcher.py
local-test-tika-full-01-vuln_0/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())