Add files using upload-large-folder tool
Browse files- local-test-tika-delta-04/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc +0 -0
- local-test-tika-delta-04/fuzz-tooling/infra/base-images/all.sh +28 -0
- local-test-tika-delta-04/fuzz-tooling/infra/build_specified_commit.py +410 -0
- local-test-tika-delta-04/fuzz-tooling/infra/cifuzz/requirements.txt +4 -0
- local-test-tika-delta-04/fuzz-tooling/infra/experimental/SystemSan/PoEs/node-shell-quote-v1.7.3/build.sh +22 -0
- local-test-tika-delta-04/fuzz-tooling/infra/experimental/SystemSan/PoEs/node-shell-quote-v1.7.3/target.js +35 -0
- local-test-tika-delta-04/fuzz-tooling/infra/experimental/chronos/build_on_cloudbuild.sh +26 -0
- local-test-tika-delta-04/fuzz-tooling/infra/experimental/chronos/prepare-replay-rebuild +21 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/.prettierrc.js +18 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspaceCFLite.ts +49 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts +38 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdDisplayCoverage.ts +71 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts +192 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts +59 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts +24 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts +53 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts +90 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts +300 -0
- local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/ossfuzzWrappers.ts +385 -0
local-test-tika-delta-04/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc
ADDED
|
Binary file (802 Bytes). View file
|
|
|
local-test-tika-delta-04/fuzz-tooling/infra/base-images/all.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
docker build --pull -t ghcr.io/aixcc-finals/base-image "$@" infra/base-images/base-image
|
| 19 |
+
docker build -t ghcr.io/aixcc-finals/base-clang "$@" infra/base-images/base-clang
|
| 20 |
+
docker build -t ghcr.io/aixcc-finals/base-builder "$@" infra/base-images/base-builder
|
| 21 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-go "$@" infra/base-images/base-builder-go
|
| 22 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-jvm "$@" infra/base-images/base-builder-jvm
|
| 23 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-python "$@" infra/base-images/base-builder-python
|
| 24 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-rust "$@" infra/base-images/base-builder-rust
|
| 25 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-ruby "$@" infra/base-images/base-builder-ruby
|
| 26 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-swift "$@" infra/base-images/base-builder-swift
|
| 27 |
+
docker build -t ghcr.io/aixcc-finals/base-runner "$@" infra/base-images/base-runner
|
| 28 |
+
docker build -t ghcr.io/aixcc-finals/base-runner-debug "$@" infra/base-images/base-runner-debug
|
local-test-tika-delta-04/fuzz-tooling/infra/build_specified_commit.py
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019 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 to build a image from a specific commit, branch or pull request.
|
| 15 |
+
|
| 16 |
+
This module is allows each of the OSS Fuzz projects fuzzers to be built
|
| 17 |
+
from a specific point in time. This feature can be used for implementations
|
| 18 |
+
like continuious integration fuzzing and bisection to find errors
|
| 19 |
+
"""
|
| 20 |
+
import argparse
|
| 21 |
+
import bisect
|
| 22 |
+
import datetime
|
| 23 |
+
import os
|
| 24 |
+
import collections
|
| 25 |
+
import json
|
| 26 |
+
import logging
|
| 27 |
+
import re
|
| 28 |
+
import shutil
|
| 29 |
+
import tempfile
|
| 30 |
+
|
| 31 |
+
import helper
|
| 32 |
+
import repo_manager
|
| 33 |
+
import retry
|
| 34 |
+
import utils
|
| 35 |
+
|
| 36 |
+
BuildData = collections.namedtuple(
|
| 37 |
+
'BuildData', ['project_name', 'engine', 'sanitizer', 'architecture'])
|
| 38 |
+
|
| 39 |
+
_GIT_DIR_MARKER = 'gitdir: '
|
| 40 |
+
_IMAGE_BUILD_TRIES = 3
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class BaseBuilderRepo:
|
| 44 |
+
"""Repo of base-builder images."""
|
| 45 |
+
|
| 46 |
+
def __init__(self):
|
| 47 |
+
self.timestamps = []
|
| 48 |
+
self.digests = []
|
| 49 |
+
|
| 50 |
+
def add_digest(self, timestamp, digest):
|
| 51 |
+
"""Add a digest."""
|
| 52 |
+
self.timestamps.append(timestamp)
|
| 53 |
+
self.digests.append(digest)
|
| 54 |
+
|
| 55 |
+
def find_digest(self, timestamp):
|
| 56 |
+
"""Find the latest image before the given timestamp."""
|
| 57 |
+
index = bisect.bisect_right(self.timestamps, timestamp)
|
| 58 |
+
if index > 0:
|
| 59 |
+
return self.digests[index - 1]
|
| 60 |
+
|
| 61 |
+
logging.error('Failed to find suitable base-builder.')
|
| 62 |
+
return None
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _replace_gitdir(src_dir, file_path):
|
| 66 |
+
"""Replace gitdir with a relative path."""
|
| 67 |
+
with open(file_path) as handle:
|
| 68 |
+
lines = handle.readlines()
|
| 69 |
+
|
| 70 |
+
new_lines = []
|
| 71 |
+
for line in lines:
|
| 72 |
+
if line.startswith(_GIT_DIR_MARKER):
|
| 73 |
+
absolute_path = line[len(_GIT_DIR_MARKER):].strip()
|
| 74 |
+
if not os.path.isabs(absolute_path):
|
| 75 |
+
# Already relative.
|
| 76 |
+
return
|
| 77 |
+
|
| 78 |
+
current_dir = os.path.dirname(file_path)
|
| 79 |
+
# Rebase to /src rather than the host src dir.
|
| 80 |
+
base_dir = current_dir.replace(src_dir, '/src')
|
| 81 |
+
relative_path = os.path.relpath(absolute_path, base_dir)
|
| 82 |
+
logging.info('Replacing absolute submodule gitdir from %s to %s',
|
| 83 |
+
absolute_path, relative_path)
|
| 84 |
+
|
| 85 |
+
line = _GIT_DIR_MARKER + relative_path
|
| 86 |
+
|
| 87 |
+
new_lines.append(line)
|
| 88 |
+
|
| 89 |
+
with open(file_path, 'w') as handle:
|
| 90 |
+
handle.write(''.join(new_lines))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _make_gitdirs_relative(src_dir):
|
| 94 |
+
"""Make gitdirs relative."""
|
| 95 |
+
for root_dir, _, files in os.walk(src_dir):
|
| 96 |
+
for filename in files:
|
| 97 |
+
if filename != '.git':
|
| 98 |
+
continue
|
| 99 |
+
|
| 100 |
+
file_path = os.path.join(root_dir, filename)
|
| 101 |
+
_replace_gitdir(src_dir, file_path)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _replace_base_builder_digest(dockerfile_path, digest):
|
| 105 |
+
"""Replace the base-builder digest in a Dockerfile."""
|
| 106 |
+
with open(dockerfile_path) as handle:
|
| 107 |
+
lines = handle.readlines()
|
| 108 |
+
|
| 109 |
+
new_lines = []
|
| 110 |
+
for line in lines:
|
| 111 |
+
if line.strip().startswith('FROM'):
|
| 112 |
+
line = 'FROM ghcr.io/aixcc-finals/base-builder@' + digest + '\n'
|
| 113 |
+
|
| 114 |
+
new_lines.append(line)
|
| 115 |
+
|
| 116 |
+
with open(dockerfile_path, 'w') as handle:
|
| 117 |
+
handle.write(''.join(new_lines))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def copy_src_from_docker(project_name, host_dir):
|
| 121 |
+
"""Copy /src from docker to the host."""
|
| 122 |
+
# Copy /src to host.
|
| 123 |
+
image_name = 'gcr.io/oss-fuzz/' + project_name
|
| 124 |
+
src_dir = os.path.join(host_dir, 'src')
|
| 125 |
+
if os.path.exists(src_dir):
|
| 126 |
+
shutil.rmtree(src_dir, ignore_errors=True)
|
| 127 |
+
|
| 128 |
+
docker_args = [
|
| 129 |
+
'-v',
|
| 130 |
+
host_dir + ':/out',
|
| 131 |
+
image_name,
|
| 132 |
+
'cp',
|
| 133 |
+
'-r',
|
| 134 |
+
'-p',
|
| 135 |
+
'/src',
|
| 136 |
+
'/out',
|
| 137 |
+
]
|
| 138 |
+
helper.docker_run(docker_args)
|
| 139 |
+
|
| 140 |
+
# Submodules can have gitdir entries which point to absolute paths. Make them
|
| 141 |
+
# relative, as otherwise we can't do operations on the checkout on the host.
|
| 142 |
+
_make_gitdirs_relative(src_dir)
|
| 143 |
+
return src_dir
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
@retry.wrap(_IMAGE_BUILD_TRIES, 2)
|
| 147 |
+
def _build_image_with_retries(project_name):
|
| 148 |
+
"""Build image with retries."""
|
| 149 |
+
return helper.build_image_impl(helper.Project(project_name))
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def get_required_post_checkout_steps(dockerfile_path):
|
| 153 |
+
"""Get required post checkout steps (best effort)."""
|
| 154 |
+
|
| 155 |
+
checkout_pattern = re.compile(r'\s*RUN\s*(git|svn|hg)')
|
| 156 |
+
|
| 157 |
+
# If the build.sh is copied from upstream, we need to copy it again after
|
| 158 |
+
# changing the revision to ensure correct building.
|
| 159 |
+
post_run_pattern = re.compile(r'\s*RUN\s*(.*build\.sh.*(\$SRC|/src).*)')
|
| 160 |
+
|
| 161 |
+
with open(dockerfile_path) as handle:
|
| 162 |
+
lines = handle.readlines()
|
| 163 |
+
|
| 164 |
+
subsequent_run_cmds = []
|
| 165 |
+
for i, line in enumerate(lines):
|
| 166 |
+
if checkout_pattern.match(line):
|
| 167 |
+
subsequent_run_cmds = []
|
| 168 |
+
continue
|
| 169 |
+
|
| 170 |
+
match = post_run_pattern.match(line)
|
| 171 |
+
if match:
|
| 172 |
+
workdir = helper.workdir_from_lines(lines[:i])
|
| 173 |
+
command = match.group(1)
|
| 174 |
+
subsequent_run_cmds.append((workdir, command))
|
| 175 |
+
|
| 176 |
+
return subsequent_run_cmds
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
# pylint: disable=too-many-locals
|
| 180 |
+
def build_fuzzers_from_commit(commit,
|
| 181 |
+
build_repo_manager,
|
| 182 |
+
host_src_path,
|
| 183 |
+
build_data,
|
| 184 |
+
base_builder_repo=None):
|
| 185 |
+
"""Builds a OSS-Fuzz fuzzer at a specific commit SHA.
|
| 186 |
+
|
| 187 |
+
Args:
|
| 188 |
+
commit: The commit SHA to build the fuzzers at.
|
| 189 |
+
build_repo_manager: The OSS-Fuzz project's repo manager to be built at.
|
| 190 |
+
build_data: A struct containing project build information.
|
| 191 |
+
base_builder_repo: A BaseBuilderRepo.
|
| 192 |
+
Returns:
|
| 193 |
+
0 on successful build or error code on failure.
|
| 194 |
+
"""
|
| 195 |
+
oss_fuzz_repo_manager = repo_manager.RepoManager(helper.OSS_FUZZ_DIR)
|
| 196 |
+
num_retry = 1
|
| 197 |
+
|
| 198 |
+
def cleanup():
|
| 199 |
+
# Re-copy /src for a clean checkout every time.
|
| 200 |
+
copy_src_from_docker(build_data.project_name,
|
| 201 |
+
os.path.dirname(host_src_path))
|
| 202 |
+
build_repo_manager.fetch_all_remotes()
|
| 203 |
+
|
| 204 |
+
projects_dir = os.path.join('projects', build_data.project_name)
|
| 205 |
+
dockerfile_path = os.path.join(projects_dir, 'Dockerfile')
|
| 206 |
+
|
| 207 |
+
for i in range(num_retry + 1):
|
| 208 |
+
build_repo_manager.checkout_commit(commit, clean=False)
|
| 209 |
+
|
| 210 |
+
post_checkout_steps = get_required_post_checkout_steps(dockerfile_path)
|
| 211 |
+
for workdir, post_checkout_step in post_checkout_steps:
|
| 212 |
+
logging.info('Running post-checkout step `%s` in %s.', post_checkout_step,
|
| 213 |
+
workdir)
|
| 214 |
+
helper.docker_run([
|
| 215 |
+
'-w',
|
| 216 |
+
workdir,
|
| 217 |
+
'-v',
|
| 218 |
+
host_src_path + ':' + '/src',
|
| 219 |
+
'gcr.io/oss-fuzz/' + build_data.project_name,
|
| 220 |
+
'/bin/bash',
|
| 221 |
+
'-c',
|
| 222 |
+
post_checkout_step,
|
| 223 |
+
])
|
| 224 |
+
|
| 225 |
+
project = helper.Project(build_data.project_name)
|
| 226 |
+
result = helper.build_fuzzers_impl(project=project,
|
| 227 |
+
clean=True,
|
| 228 |
+
engine=build_data.engine,
|
| 229 |
+
sanitizer=build_data.sanitizer,
|
| 230 |
+
architecture=build_data.architecture,
|
| 231 |
+
env_to_add=None,
|
| 232 |
+
source_path=host_src_path,
|
| 233 |
+
mount_path='/src')
|
| 234 |
+
if result or i == num_retry:
|
| 235 |
+
break
|
| 236 |
+
|
| 237 |
+
# Retry with an OSS-Fuzz builder container that's closer to the project
|
| 238 |
+
# commit date.
|
| 239 |
+
commit_date = build_repo_manager.commit_date(commit)
|
| 240 |
+
|
| 241 |
+
# Find first change in the projects/<PROJECT> directory before the project
|
| 242 |
+
# commit date.
|
| 243 |
+
oss_fuzz_commit, _, _ = oss_fuzz_repo_manager.git([
|
| 244 |
+
'log', '--before=' + commit_date.isoformat(), '-n1', '--format=%H',
|
| 245 |
+
projects_dir
|
| 246 |
+
],
|
| 247 |
+
check_result=True)
|
| 248 |
+
oss_fuzz_commit = oss_fuzz_commit.strip()
|
| 249 |
+
if not oss_fuzz_commit:
|
| 250 |
+
logging.info(
|
| 251 |
+
'Could not find first OSS-Fuzz commit prior to upstream commit. '
|
| 252 |
+
'Falling back to oldest integration commit.')
|
| 253 |
+
|
| 254 |
+
# Find the oldest commit.
|
| 255 |
+
oss_fuzz_commit, _, _ = oss_fuzz_repo_manager.git(
|
| 256 |
+
['log', '--reverse', '--format=%H', projects_dir], check_result=True)
|
| 257 |
+
|
| 258 |
+
oss_fuzz_commit = oss_fuzz_commit.splitlines()[0].strip()
|
| 259 |
+
|
| 260 |
+
if not oss_fuzz_commit:
|
| 261 |
+
logging.error('Failed to get oldest integration commit.')
|
| 262 |
+
break
|
| 263 |
+
|
| 264 |
+
logging.info('Build failed. Retrying on earlier OSS-Fuzz commit %s.',
|
| 265 |
+
oss_fuzz_commit)
|
| 266 |
+
|
| 267 |
+
# Check out projects/<PROJECT> dir to the commit that was found.
|
| 268 |
+
oss_fuzz_repo_manager.git(['checkout', oss_fuzz_commit, projects_dir],
|
| 269 |
+
check_result=True)
|
| 270 |
+
|
| 271 |
+
# Also use the closest base-builder we can find.
|
| 272 |
+
if base_builder_repo:
|
| 273 |
+
base_builder_digest = base_builder_repo.find_digest(commit_date)
|
| 274 |
+
if not base_builder_digest:
|
| 275 |
+
return False
|
| 276 |
+
|
| 277 |
+
logging.info('Using base-builder with digest %s.', base_builder_digest)
|
| 278 |
+
_replace_base_builder_digest(dockerfile_path, base_builder_digest)
|
| 279 |
+
|
| 280 |
+
# Rebuild image and re-copy src dir since things in /src could have changed.
|
| 281 |
+
if not _build_image_with_retries(build_data.project_name):
|
| 282 |
+
logging.error('Failed to rebuild image.')
|
| 283 |
+
return False
|
| 284 |
+
|
| 285 |
+
cleanup()
|
| 286 |
+
|
| 287 |
+
cleanup()
|
| 288 |
+
return result
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def detect_main_repo(project_name, repo_name=None, commit=None):
|
| 292 |
+
"""Checks a docker image for the main repo of an OSS-Fuzz project.
|
| 293 |
+
|
| 294 |
+
Note: The default is to use the repo name to detect the main repo.
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
project_name: The name of the oss-fuzz project.
|
| 298 |
+
repo_name: The name of the main repo in an OSS-Fuzz project.
|
| 299 |
+
commit: A commit SHA that is associated with the main repo.
|
| 300 |
+
|
| 301 |
+
Returns:
|
| 302 |
+
A tuple containing (the repo's origin, the repo's path).
|
| 303 |
+
"""
|
| 304 |
+
|
| 305 |
+
if not repo_name and not commit:
|
| 306 |
+
logging.error(
|
| 307 |
+
'Error: can not detect main repo without a repo_name or a commit.')
|
| 308 |
+
return None, None
|
| 309 |
+
if repo_name and commit:
|
| 310 |
+
logging.info(
|
| 311 |
+
'Both repo name and commit specific. Using repo name for detection.')
|
| 312 |
+
|
| 313 |
+
# Change to oss-fuzz main directory so helper.py runs correctly.
|
| 314 |
+
utils.chdir_to_root()
|
| 315 |
+
if not _build_image_with_retries(project_name):
|
| 316 |
+
logging.error('Error: building %s image failed.', project_name)
|
| 317 |
+
return None, None
|
| 318 |
+
docker_image_name = 'gcr.io/oss-fuzz/' + project_name
|
| 319 |
+
command_to_run = [
|
| 320 |
+
'docker', 'run', '--rm', '-t', docker_image_name, 'python3',
|
| 321 |
+
os.path.join('/opt', 'cifuzz', 'detect_repo.py')
|
| 322 |
+
]
|
| 323 |
+
if repo_name:
|
| 324 |
+
command_to_run.extend(['--repo_name', repo_name])
|
| 325 |
+
else:
|
| 326 |
+
command_to_run.extend(['--example_commit', commit])
|
| 327 |
+
out, _, _ = utils.execute(command_to_run)
|
| 328 |
+
match = re.search(r'\bDetected repo: ([^ ]+) ([^ ]+)', out.rstrip())
|
| 329 |
+
if match and match.group(1) and match.group(2):
|
| 330 |
+
return match.group(1), match.group(2)
|
| 331 |
+
|
| 332 |
+
logging.error('Failed to detect repo:\n%s', out)
|
| 333 |
+
return None, None
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def load_base_builder_repo():
|
| 337 |
+
"""Get base-image digests."""
|
| 338 |
+
gcloud_path = shutil.which('gcloud')
|
| 339 |
+
if not gcloud_path:
|
| 340 |
+
logging.warning('gcloud not found in PATH.')
|
| 341 |
+
return None
|
| 342 |
+
|
| 343 |
+
result, _, _ = utils.execute([
|
| 344 |
+
gcloud_path,
|
| 345 |
+
'container',
|
| 346 |
+
'images',
|
| 347 |
+
'list-tags',
|
| 348 |
+
'ghcr.io/aixcc-finals/base-builder',
|
| 349 |
+
'--format=json',
|
| 350 |
+
'--sort-by=timestamp',
|
| 351 |
+
],
|
| 352 |
+
check_result=True)
|
| 353 |
+
result = json.loads(result)
|
| 354 |
+
|
| 355 |
+
repo = BaseBuilderRepo()
|
| 356 |
+
for image in result:
|
| 357 |
+
timestamp = datetime.datetime.fromisoformat(
|
| 358 |
+
image['timestamp']['datetime']).astimezone(datetime.timezone.utc)
|
| 359 |
+
repo.add_digest(timestamp, image['digest'])
|
| 360 |
+
|
| 361 |
+
return repo
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def main():
|
| 365 |
+
"""Main function."""
|
| 366 |
+
logging.getLogger().setLevel(logging.INFO)
|
| 367 |
+
|
| 368 |
+
parser = argparse.ArgumentParser(
|
| 369 |
+
description='Build fuzzers at a specific commit')
|
| 370 |
+
parser.add_argument('--project_name',
|
| 371 |
+
help='The name of the project where the bug occurred.',
|
| 372 |
+
required=True)
|
| 373 |
+
parser.add_argument('--commit',
|
| 374 |
+
help='The newest commit SHA to be bisected.',
|
| 375 |
+
required=True)
|
| 376 |
+
parser.add_argument('--engine',
|
| 377 |
+
help='The default is "libfuzzer".',
|
| 378 |
+
default='libfuzzer')
|
| 379 |
+
parser.add_argument('--sanitizer',
|
| 380 |
+
default='address',
|
| 381 |
+
help='The default is "address".')
|
| 382 |
+
parser.add_argument('--architecture', default='x86_64')
|
| 383 |
+
|
| 384 |
+
args = parser.parse_args()
|
| 385 |
+
|
| 386 |
+
repo_url, repo_path = detect_main_repo(args.project_name, commit=args.commit)
|
| 387 |
+
|
| 388 |
+
if not repo_url or not repo_path:
|
| 389 |
+
raise ValueError('Main git repo can not be determined.')
|
| 390 |
+
|
| 391 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 392 |
+
host_src_dir = copy_src_from_docker(args.project_name, tmp_dir)
|
| 393 |
+
build_repo_manager = repo_manager.RepoManager(
|
| 394 |
+
os.path.join(host_src_dir, os.path.basename(repo_path)))
|
| 395 |
+
base_builder_repo = load_base_builder_repo()
|
| 396 |
+
|
| 397 |
+
build_data = BuildData(project_name=args.project_name,
|
| 398 |
+
engine=args.engine,
|
| 399 |
+
sanitizer=args.sanitizer,
|
| 400 |
+
architecture=args.architecture)
|
| 401 |
+
if not build_fuzzers_from_commit(args.commit,
|
| 402 |
+
build_repo_manager,
|
| 403 |
+
host_src_dir,
|
| 404 |
+
build_data,
|
| 405 |
+
base_builder_repo=base_builder_repo):
|
| 406 |
+
raise RuntimeError('Failed to build.')
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
if __name__ == '__main__':
|
| 410 |
+
main()
|
local-test-tika-delta-04/fuzz-tooling/infra/cifuzz/requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
clusterfuzz==2.5.9
|
| 2 |
+
requests==2.28.0
|
| 3 |
+
protobuf==3.20.2
|
| 4 |
+
gsutil==5.20
|
local-test-tika-delta-04/fuzz-tooling/infra/experimental/SystemSan/PoEs/node-shell-quote-v1.7.3/build.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 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 |
+
# Build and install project (using current CFLAGS, CXXFLAGS).
|
| 19 |
+
npm install ./node-shell-quote/
|
| 20 |
+
|
| 21 |
+
# Build fuzzers.
|
| 22 |
+
npm i -g @gitlab-org/jsfuzz
|
local-test-tika-delta-04/fuzz-tooling/infra/experimental/SystemSan/PoEs/node-shell-quote-v1.7.3/target.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 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 |
+
/* Exploit shell quote with fuzzer's input as a parameter of echo.
|
| 17 |
+
* This PoC is extended from a report in GitHub Advisory Database:
|
| 18 |
+
* https://github.com/advisories/GHSA-g4rg-993r-mgx7
|
| 19 |
+
* The original report records a shell injection exploit in shell-quote v1.7.2,
|
| 20 |
+
* we show that a similar shell corruption exploit still persists in v1.7.3,
|
| 21 |
+
* after a commit that intends to fix the original exploit.
|
| 22 |
+
* */
|
| 23 |
+
|
| 24 |
+
/* Fuzz the target program with buf generated by Jsfuzz. */
|
| 25 |
+
function fuzz(buf) {
|
| 26 |
+
buf = String(buf)
|
| 27 |
+
const childProcess = require('child_process');
|
| 28 |
+
const shellQuote = require('shell-quote');
|
| 29 |
+
childProcess.execSync(shellQuote.quote(['echo', buf]));
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/* Run Jsfuzz. */
|
| 33 |
+
module.exports = {
|
| 34 |
+
fuzz
|
| 35 |
+
};
|
local-test-tika-delta-04/fuzz-tooling/infra/experimental/chronos/build_on_cloudbuild.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/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 |
+
PROJECT=$1
|
| 18 |
+
FUZZING_LANGUAGE=$2
|
| 19 |
+
|
| 20 |
+
gcloud builds submit "https://github.com/google/oss-fuzz" \
|
| 21 |
+
--async \
|
| 22 |
+
--git-source-revision=master \
|
| 23 |
+
--config=cloudbuild.yaml \
|
| 24 |
+
--substitutions=_PROJECT=$PROJECT,_FUZZING_LANGUAGE=$FUZZING_LANGUAGE \
|
| 25 |
+
--project=oss-fuzz \
|
| 26 |
+
--region=us-central1
|
local-test-tika-delta-04/fuzz-tooling/infra/experimental/chronos/prepare-replay-rebuild
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/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 |
+
PROJECT=$1
|
| 19 |
+
{
|
| 20 |
+
echo "ENV REPLAY_ENABLED=1";
|
| 21 |
+
} >> "projects/$PROJECT/Dockerfile"
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/.prettierrc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
module.exports = {
|
| 17 |
+
...require('gts/.prettierrc.json')
|
| 18 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspaceCFLite.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 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 |
+
import {commandHistory} from '../commandUtils';
|
| 19 |
+
import {setStatusText} from '../utils';
|
| 20 |
+
import {buildFuzzersFromWorkspaceClusterfuzzLite} from '../ossfuzzWrappers';
|
| 21 |
+
|
| 22 |
+
export async function cmdInputCollectorBuildFuzzersFromWorkspaceCFLite() {
|
| 23 |
+
// Create an history object
|
| 24 |
+
const args = new Object({
|
| 25 |
+
toClean: false,
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
const commandObject = new Object({
|
| 29 |
+
commandType: 'oss-fuzz.WSBuildFuzzers',
|
| 30 |
+
Arguments: args,
|
| 31 |
+
dispatcherFunc: cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite,
|
| 32 |
+
});
|
| 33 |
+
console.log('L1: ' + commandHistory.length);
|
| 34 |
+
commandHistory.push(commandObject);
|
| 35 |
+
|
| 36 |
+
await cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite(args);
|
| 37 |
+
return true;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 41 |
+
async function cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite(_args: any) {
|
| 42 |
+
await setStatusText('[CFLite] Building fuzzers: starting');
|
| 43 |
+
const res = await buildFuzzersFromWorkspaceClusterfuzzLite();
|
| 44 |
+
if (res) {
|
| 45 |
+
await setStatusText('[CFLite] Building fuzzers: finished');
|
| 46 |
+
} else {
|
| 47 |
+
await setStatusText('[CFLite] Building fuzzers: failed');
|
| 48 |
+
}
|
| 49 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
/**
|
| 18 |
+
* Command for generating template fuzzers. This is a short-cut for rapid
|
| 19 |
+
* prototyping as well as an archive for inspiration.
|
| 20 |
+
*/
|
| 21 |
+
import * as vscode from 'vscode';
|
| 22 |
+
import {setStatusText} from '../utils';
|
| 23 |
+
|
| 24 |
+
import {setupProjectInitialFiles} from '../projectIntegrationHelper';
|
| 25 |
+
|
| 26 |
+
export async function cmdDispatcherGenerateClusterfuzzLite(
|
| 27 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 28 |
+
_context: vscode.ExtensionContext
|
| 29 |
+
) {
|
| 30 |
+
await setStatusText('Creating OSS-Fuzz setup: starting');
|
| 31 |
+
const res = await setupProjectInitialFiles(true);
|
| 32 |
+
if (res) {
|
| 33 |
+
await setStatusText('Creating OSS-Fuzz setup: finished');
|
| 34 |
+
} else {
|
| 35 |
+
await setStatusText('Creating OSS-Fuzz setup: failed');
|
| 36 |
+
}
|
| 37 |
+
return;
|
| 38 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdDisplayCoverage.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {loadCoverageIntoWorkspace} from '../coverageHelper';
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {getApi, FileDownloader} from '@microsoft/vscode-file-downloader-api';
|
| 21 |
+
|
| 22 |
+
/*
|
| 23 |
+
* Displays code coverage from OSS-Fuzz.
|
| 24 |
+
*
|
| 25 |
+
* Downloads a code coverage report from the OSS-Fuzz online storage, and then overlays
|
| 26 |
+
* the relevant source files with the coverage information.
|
| 27 |
+
*/
|
| 28 |
+
export async function displayCodeCoverageFromOssFuzz(
|
| 29 |
+
context: vscode.ExtensionContext
|
| 30 |
+
) {
|
| 31 |
+
const projectName = await vscode.window.showInputBox({
|
| 32 |
+
value: '',
|
| 33 |
+
placeHolder: "The project you'd like to get code coverage for.",
|
| 34 |
+
});
|
| 35 |
+
if (!projectName) {
|
| 36 |
+
return;
|
| 37 |
+
}
|
| 38 |
+
println('Getting code coverage for ' + projectName);
|
| 39 |
+
|
| 40 |
+
const fileDownloader: FileDownloader = await getApi();
|
| 41 |
+
|
| 42 |
+
const currentDate = new Date();
|
| 43 |
+
const yesterday = new Date(currentDate);
|
| 44 |
+
yesterday.setDate(yesterday.getDate() - 1);
|
| 45 |
+
|
| 46 |
+
const day = yesterday.getDate();
|
| 47 |
+
const month = yesterday.getMonth();
|
| 48 |
+
const year = yesterday.getFullYear();
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
const codeCoverageFile: vscode.Uri = await fileDownloader.downloadFile(
|
| 52 |
+
vscode.Uri.parse(
|
| 53 |
+
'https://storage.googleapis.com/oss-fuzz-coverage/' +
|
| 54 |
+
projectName +
|
| 55 |
+
'/textcov_reports/' +
|
| 56 |
+
year.toString() +
|
| 57 |
+
month.toString() +
|
| 58 |
+
day.toString() +
|
| 59 |
+
'/all_cov.json'
|
| 60 |
+
),
|
| 61 |
+
'all_cov.json',
|
| 62 |
+
context
|
| 63 |
+
);
|
| 64 |
+
await loadCoverageIntoWorkspace(context, codeCoverageFile);
|
| 65 |
+
} catch (err) {
|
| 66 |
+
println(
|
| 67 |
+
'Could not get the URL. Currently, this feature is only supported for Python projects'
|
| 68 |
+
);
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {commandHistory} from '../commandUtils';
|
| 21 |
+
import {buildFuzzersFromWorkspace, runFuzzerHandler} from '../ossfuzzWrappers';
|
| 22 |
+
import {listFuzzersForProject, systemSync, setStatusText} from '../utils';
|
| 23 |
+
import {
|
| 24 |
+
compareLocalToRemoteCoverage,
|
| 25 |
+
loadCoverageIntoWorkspace,
|
| 26 |
+
} from '../coverageHelper';
|
| 27 |
+
import {extensionConfig} from '../config';
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Performs the activities:
|
| 31 |
+
* 1) Build a project using address sanitizer
|
| 32 |
+
* 2) Run each fuzzer of the project, saving corpus
|
| 33 |
+
* 3) Build project using coverage sanitizer
|
| 34 |
+
* 4) Collect coverage
|
| 35 |
+
* @param context
|
| 36 |
+
* @returns
|
| 37 |
+
*/
|
| 38 |
+
export async function runEndToEndAndGetCoverage(
|
| 39 |
+
context: vscode.ExtensionContext
|
| 40 |
+
) {
|
| 41 |
+
println('Getting code coverage');
|
| 42 |
+
await setStatusText('end-to-end coverage: getting input');
|
| 43 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 44 |
+
value: '',
|
| 45 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 46 |
+
});
|
| 47 |
+
if (!ossFuzzProjectNameInput) {
|
| 48 |
+
println('Did not get a ossFuzzTargetProject');
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
const secondsToRunEachFuzzer = await vscode.window.showInputBox({
|
| 52 |
+
value: '',
|
| 53 |
+
placeHolder: 'Seconds to run each fuzzer',
|
| 54 |
+
});
|
| 55 |
+
if (!secondsToRunEachFuzzer) {
|
| 56 |
+
println('Did not get number of seconds to run each fuzzer');
|
| 57 |
+
return;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Create an history object
|
| 61 |
+
const args = new Object({
|
| 62 |
+
projectName: ossFuzzProjectNameInput.toString(),
|
| 63 |
+
secondsToRun: secondsToRunEachFuzzer.toString(),
|
| 64 |
+
vsContext: context,
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const commandObject = new Object({
|
| 68 |
+
commandType: 'oss-fuzz.cmdDispatchEndToEndRun',
|
| 69 |
+
Arguments: args,
|
| 70 |
+
dispatcherFunc: cmdDispatchEndToEndRun,
|
| 71 |
+
});
|
| 72 |
+
console.log('L1: ' + commandHistory.length);
|
| 73 |
+
commandHistory.push(commandObject);
|
| 74 |
+
|
| 75 |
+
await cmdDispatchEndToEndRun(args);
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
async function cmdDispatchEndToEndRun(args: any) {
|
| 80 |
+
await setStatusText('end-to-end coverage: starting');
|
| 81 |
+
const res = await endToEndRun(
|
| 82 |
+
args.projectName,
|
| 83 |
+
args.secondsToRun,
|
| 84 |
+
args.vsContext
|
| 85 |
+
);
|
| 86 |
+
if (res) {
|
| 87 |
+
await setStatusText('end-to-end coverage: finished succesfully');
|
| 88 |
+
} else {
|
| 89 |
+
await setStatusText('end-to-end coverage: failed');
|
| 90 |
+
}
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
async function endToEndRun(
|
| 95 |
+
ossFuzzProjectNameInput: string,
|
| 96 |
+
secondsToRunEachFuzzer: string,
|
| 97 |
+
context: vscode.ExtensionContext
|
| 98 |
+
) {
|
| 99 |
+
await setStatusText('end-to-end coverage: build with ASAN');
|
| 100 |
+
vscode.window.showInformationMessage(
|
| 101 |
+
'Building project: ' + ossFuzzProjectNameInput.toString()
|
| 102 |
+
);
|
| 103 |
+
if (
|
| 104 |
+
(await buildFuzzersFromWorkspace(
|
| 105 |
+
ossFuzzProjectNameInput.toString(),
|
| 106 |
+
'',
|
| 107 |
+
true
|
| 108 |
+
)) === false
|
| 109 |
+
) {
|
| 110 |
+
println('Failed to build project');
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
println('Build projects');
|
| 114 |
+
|
| 115 |
+
// List all of the fuzzers in the project
|
| 116 |
+
const fuzzersInProject = await listFuzzersForProject(
|
| 117 |
+
ossFuzzProjectNameInput,
|
| 118 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 119 |
+
);
|
| 120 |
+
|
| 121 |
+
// Run all of the fuzzers in the project
|
| 122 |
+
await setStatusText('end-to-end coverage: collecting corpus');
|
| 123 |
+
println('Fuzzers found in project: ' + fuzzersInProject.toString());
|
| 124 |
+
println('Running each of the fuzzers to collect a corpus');
|
| 125 |
+
for (const fuzzName of fuzzersInProject) {
|
| 126 |
+
println('Running fuzzer: ' + fuzzName);
|
| 127 |
+
await setStatusText('end-to-end coverage: collecting corpus: ' + fuzzName);
|
| 128 |
+
// Corpus directory
|
| 129 |
+
const fuzzerCorpusPath =
|
| 130 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 131 |
+
'/build/corpus/' +
|
| 132 |
+
ossFuzzProjectNameInput +
|
| 133 |
+
'/' +
|
| 134 |
+
fuzzName;
|
| 135 |
+
|
| 136 |
+
await systemSync('mkdir', ['-p', fuzzerCorpusPath]);
|
| 137 |
+
|
| 138 |
+
await runFuzzerHandler(
|
| 139 |
+
ossFuzzProjectNameInput,
|
| 140 |
+
fuzzName,
|
| 141 |
+
secondsToRunEachFuzzer.toString(),
|
| 142 |
+
fuzzerCorpusPath
|
| 143 |
+
);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Build with code coverage
|
| 147 |
+
println('Building project with coverage sanitizer');
|
| 148 |
+
await setStatusText('end-to-end coverage: building with coverage');
|
| 149 |
+
await buildFuzzersFromWorkspace(
|
| 150 |
+
ossFuzzProjectNameInput.toString(),
|
| 151 |
+
'coverage',
|
| 152 |
+
true
|
| 153 |
+
);
|
| 154 |
+
|
| 155 |
+
// Run coverage command
|
| 156 |
+
println('Collecting code coverage');
|
| 157 |
+
await setStatusText('end-to-end coverage: collecting coverage');
|
| 158 |
+
const args: Array<string> = [
|
| 159 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 160 |
+
'coverage',
|
| 161 |
+
'--port',
|
| 162 |
+
'',
|
| 163 |
+
'--no-corpus-download',
|
| 164 |
+
ossFuzzProjectNameInput.toString(),
|
| 165 |
+
];
|
| 166 |
+
await systemSync('python3', args);
|
| 167 |
+
await setStatusText('end-to-end coverage: finished collecting coverage');
|
| 168 |
+
println('Load coverage report with the command:');
|
| 169 |
+
println(
|
| 170 |
+
'python3 -m http.server 8008 --directory /tmp/oss-fuzz/build/out/' +
|
| 171 |
+
ossFuzzProjectNameInput.toString() +
|
| 172 |
+
'/report/'
|
| 173 |
+
);
|
| 174 |
+
|
| 175 |
+
println('Trying to load code coverage in IDE');
|
| 176 |
+
const allCovPath =
|
| 177 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 178 |
+
'/build/out/' +
|
| 179 |
+
ossFuzzProjectNameInput.toString() +
|
| 180 |
+
'/textcov_reports/all_cov.json';
|
| 181 |
+
if (fs.existsSync(allCovPath)) {
|
| 182 |
+
const generatedCodeCoverageFile = vscode.Uri.file(allCovPath);
|
| 183 |
+
await loadCoverageIntoWorkspace(context, generatedCodeCoverageFile);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
await compareLocalToRemoteCoverage(
|
| 187 |
+
context,
|
| 188 |
+
ossFuzzProjectNameInput.toString()
|
| 189 |
+
);
|
| 190 |
+
|
| 191 |
+
return true;
|
| 192 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {commandHistory} from '../commandUtils';
|
| 21 |
+
import {systemSyncLogIfFailure} from '../utils';
|
| 22 |
+
import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 23 |
+
import {extensionConfig} from '../config';
|
| 24 |
+
const readline = require('readline');
|
| 25 |
+
|
| 26 |
+
export async function cmdInputCollectorReproduceTestcase() {
|
| 27 |
+
// Runs a fuzzer from a given project.
|
| 28 |
+
const crashFileInput = await vscode.window.showInputBox({
|
| 29 |
+
value: '',
|
| 30 |
+
placeHolder: 'The ID of the testcase.',
|
| 31 |
+
});
|
| 32 |
+
if (!crashFileInput) {
|
| 33 |
+
return;
|
| 34 |
+
}
|
| 35 |
+
// Create an history object and append it to the command history.
|
| 36 |
+
const args = new Object({
|
| 37 |
+
crashFile: crashFileInput.toString(),
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
const commandObject = new Object({
|
| 41 |
+
commandType: 'oss-fuzz.ReproduceFuzzer',
|
| 42 |
+
Arguments: args,
|
| 43 |
+
dispatcherFunc: cmdDispatchReproduceTestcase,
|
| 44 |
+
});
|
| 45 |
+
commandHistory.push(commandObject);
|
| 46 |
+
|
| 47 |
+
await cmdDispatchReproduceTestcase(args);
|
| 48 |
+
return true;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
async function cmdDispatchReproduceTestcase(args: any) {
|
| 52 |
+
await reproduceTestcase(args.crashFile);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export async function reproduceTestcase(crashInfoFileInput: string) {
|
| 56 |
+
println('Reproducing testcase for ' + crashInfoFileInput);
|
| 57 |
+
println('Checking directory: ' + extensionConfig.crashesDirectory);
|
| 58 |
+
|
| 59 |
+
const crashInfoFile =
|
| 60 |
+
extensionConfig.crashesDirectory + '/' + crashInfoFileInput + '.info';
|
| 61 |
+
println(crashInfoFile);
|
| 62 |
+
try {
|
| 63 |
+
if (fs.existsSync(crashInfoFile)) {
|
| 64 |
+
println('File exists');
|
| 65 |
+
} else {
|
| 66 |
+
println('Crash file does not exist');
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
} catch (err) {
|
| 70 |
+
console.error(err);
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// At this point the file exists
|
| 75 |
+
const r = readline.createInterface({
|
| 76 |
+
input: fs.createReadStream(crashInfoFile),
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
let targetProject = 'N/A';
|
| 80 |
+
let targetFuzzer = 'N/A';
|
| 81 |
+
// Logic for passing the file. This is based off of clusterfuzz monorail reports,
|
| 82 |
+
// and the intention is the file needs to be a copy of:
|
| 83 |
+
//
|
| 84 |
+
// Project: project-name
|
| 85 |
+
// Fuzzing Engine: libFuzzer
|
| 86 |
+
// Fuzz Target: fuzzer-name
|
| 87 |
+
//
|
| 88 |
+
// Example:
|
| 89 |
+
// The following URL: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59747
|
| 90 |
+
// has the bug information:
|
| 91 |
+
// """
|
| 92 |
+
// Project: my-fuzzing-project
|
| 93 |
+
// Fuzzing Engine: libFuzzer
|
| 94 |
+
// Fuzz Target: the-fuzzer-name-fuzz-parseXX
|
| 95 |
+
// Job Type: libfuzzer_asan_my-fuzzing-project
|
| 96 |
+
// Platform Id: linux
|
| 97 |
+
// """
|
| 98 |
+
// and a link to a reproducer test case:
|
| 99 |
+
// https://oss-fuzz.com/download?testcase_id=5009071179431936
|
| 100 |
+
// which, when accessed will download the file
|
| 101 |
+
// clusterfuzz-testcase-minimized-flb-it-fuzz-config_map_fuzzer_OSSFUZZ-5009071179431936
|
| 102 |
+
//
|
| 103 |
+
// To enable reproducing of this issue we need to:
|
| 104 |
+
// - 1) Download the crash file and place it in the directory given in config.ts
|
| 105 |
+
// and "crashesDirectory" variable.
|
| 106 |
+
// - 2) create a file "5009071179431936.info" and paste the information above
|
| 107 |
+
// (Project:... Fuzz Target: ...) into the file. This information is
|
| 108 |
+
// needed because we need to know project name and fuzzer name in order
|
| 109 |
+
// to reproduce the crash.
|
| 110 |
+
// - 3) the reproducer can now be reproduced using the reproduce command
|
| 111 |
+
// with argument "5009071179431936" as argument.
|
| 112 |
+
r.on('line', (text: string) => {
|
| 113 |
+
println(text);
|
| 114 |
+
if (text.startsWith('Project: ')) {
|
| 115 |
+
println('Starts with project');
|
| 116 |
+
println(text.split('Project: ').toString());
|
| 117 |
+
targetProject = text.split('Project: ')[1];
|
| 118 |
+
} else if (text.startsWith('Fuzzing Engine: ')) {
|
| 119 |
+
println('Starts with fuzzing engine');
|
| 120 |
+
} else if (text.startsWith('Fuzz Target:')) {
|
| 121 |
+
println('Starts with Fuzz Target');
|
| 122 |
+
targetFuzzer = text.split('Fuzz Target: ')[1];
|
| 123 |
+
} else if (text.startsWith('Job Type:')) {
|
| 124 |
+
println('Starts with Job Type');
|
| 125 |
+
}
|
| 126 |
+
});
|
| 127 |
+
|
| 128 |
+
r.on('close', async () => {
|
| 129 |
+
println('Target project: ' + targetProject);
|
| 130 |
+
println('Target fuzzer: ' + targetFuzzer);
|
| 131 |
+
|
| 132 |
+
// Build a fresh version of the project.
|
| 133 |
+
const buildResult: boolean = await buildFuzzersFromWorkspace(
|
| 134 |
+
targetProject,
|
| 135 |
+
'',
|
| 136 |
+
true
|
| 137 |
+
);
|
| 138 |
+
if (!buildResult) {
|
| 139 |
+
println('Failed to build fuzzers');
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// We have a fresh build of the project, proceed to reproduce the testcase.
|
| 144 |
+
const crashInputTestCase =
|
| 145 |
+
extensionConfig.crashesDirectory +
|
| 146 |
+
'/' +
|
| 147 |
+
'clusterfuzz-testcase-minimized-' +
|
| 148 |
+
targetFuzzer +
|
| 149 |
+
'-' +
|
| 150 |
+
crashInfoFileInput;
|
| 151 |
+
// Run reproduce command against the target file
|
| 152 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 153 |
+
const cmdToExec = 'python3';
|
| 154 |
+
const args = [
|
| 155 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 156 |
+
'reproduce',
|
| 157 |
+
targetProject,
|
| 158 |
+
targetFuzzer,
|
| 159 |
+
crashInputTestCase,
|
| 160 |
+
];
|
| 161 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 162 |
+
println('Failed to reproduce testcase');
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return true;
|
| 166 |
+
});
|
| 167 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {extensionConfig} from '../config';
|
| 21 |
+
|
| 22 |
+
// Set the oss-fuzz path.
|
| 23 |
+
export async function setOssFuzzPath() {
|
| 24 |
+
println('Setting path');
|
| 25 |
+
const newOssFuzzPath = await vscode.window.showInputBox({
|
| 26 |
+
value: '',
|
| 27 |
+
placeHolder: 'Type path',
|
| 28 |
+
});
|
| 29 |
+
if (!newOssFuzzPath) {
|
| 30 |
+
println('Failed getting path');
|
| 31 |
+
return;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const fpathh = vscode.Uri.file(newOssFuzzPath);
|
| 35 |
+
let isValid = false;
|
| 36 |
+
try {
|
| 37 |
+
if (await vscode.workspace.fs.readDirectory(fpathh)) {
|
| 38 |
+
println('Is a directory');
|
| 39 |
+
const helperPathURI = vscode.Uri.file(
|
| 40 |
+
newOssFuzzPath + '/infra/helper.py'
|
| 41 |
+
);
|
| 42 |
+
if (await vscode.workspace.fs.readFile(helperPathURI)) {
|
| 43 |
+
println('Found helper file');
|
| 44 |
+
isValid = true;
|
| 45 |
+
}
|
| 46 |
+
isValid = true;
|
| 47 |
+
} else {
|
| 48 |
+
isValid = false;
|
| 49 |
+
}
|
| 50 |
+
} catch {
|
| 51 |
+
isValid = false;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (isValid) {
|
| 55 |
+
extensionConfig.ossFuzzPepositoryWorkPath = newOssFuzzPath;
|
| 56 |
+
} else {
|
| 57 |
+
println('Not setting OSS-Fuzz path');
|
| 58 |
+
}
|
| 59 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2024 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 |
+
import {setUpFuzzIntrospector} from '../fuzzIntrospectorHelper';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Function for setting up Fuzz Introspector by way of a Python virtual env.
|
| 21 |
+
*/
|
| 22 |
+
export async function setUpFuzzIntrospectorHandler() {
|
| 23 |
+
setUpFuzzIntrospector();
|
| 24 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import {println} from '../logger';
|
| 18 |
+
import {extensionConfig} from '../config';
|
| 19 |
+
import {isPathValidOssFuzzPath} from '../ossfuzzWrappers';
|
| 20 |
+
import {systemSync} from '../utils';
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Function for setting up oss-fuzz. This clones the relevant directory
|
| 24 |
+
* and sets the oss-fuzz variable accordingly.
|
| 25 |
+
*/
|
| 26 |
+
export async function setUpOssFuzzHandler() {
|
| 27 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 28 |
+
|
| 29 |
+
// First check if we already have an OSS-Fuzz path
|
| 30 |
+
const tmpOssFuzzRepositoryPath = '/tmp/oss-fuzz';
|
| 31 |
+
|
| 32 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 33 |
+
println('OSS-Fuzz already exists in /tmp/oss-fuzz');
|
| 34 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const cmdToExec = 'git';
|
| 39 |
+
const args: Array<string> = [
|
| 40 |
+
'clone',
|
| 41 |
+
'https://github.com/google/oss-fuzz',
|
| 42 |
+
tmpOssFuzzRepositoryPath,
|
| 43 |
+
];
|
| 44 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 45 |
+
if (res === false) {
|
| 46 |
+
println('Failed to clone oss-fuzz');
|
| 47 |
+
println(output);
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
println('Finished cloning oss-fuzz');
|
| 51 |
+
|
| 52 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 53 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {runFuzzerHandler, buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 20 |
+
import {setStatusText} from '../utils';
|
| 21 |
+
import {commandHistory} from '../commandUtils';
|
| 22 |
+
import {extensionConfig} from '../config';
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Does an end-to-end test of a project/fuzzer. This is done by
|
| 26 |
+
* first building the project and then running the fuzzer.
|
| 27 |
+
* @param context
|
| 28 |
+
* @returns
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
export async function cmdInputCollectorTestFuzzer() {
|
| 32 |
+
setStatusText('Testing specific fuzzer: getting input');
|
| 33 |
+
// Get the project name and fuzzer name to test.
|
| 34 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 35 |
+
value: '',
|
| 36 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 37 |
+
});
|
| 38 |
+
if (!ossFuzzProjectNameInput) {
|
| 39 |
+
println('Did not get a ossFuzzTargetProject');
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
println('Project name: ' + ossFuzzProjectNameInput);
|
| 43 |
+
|
| 44 |
+
// Get the fuzzer to run
|
| 45 |
+
const fuzzerNameInput = await vscode.window.showInputBox({
|
| 46 |
+
value: '',
|
| 47 |
+
placeHolder: 'Type a fuzzer name',
|
| 48 |
+
});
|
| 49 |
+
if (!fuzzerNameInput) {
|
| 50 |
+
println('Failed to get fuzzer name');
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Create the args object for the dispatcher
|
| 55 |
+
const args = new Object({
|
| 56 |
+
projectName: ossFuzzProjectNameInput.toString(),
|
| 57 |
+
fuzzerName: fuzzerNameInput.toString(),
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
// Create a dispatcher object.
|
| 61 |
+
const commandObject = new Object({
|
| 62 |
+
commandType: 'oss-fuzz.TestFuzzer',
|
| 63 |
+
Arguments: args,
|
| 64 |
+
dispatcherFunc: cmdDispatchTestFuzzerHandler,
|
| 65 |
+
});
|
| 66 |
+
commandHistory.push(commandObject);
|
| 67 |
+
|
| 68 |
+
await cmdDispatchTestFuzzerHandler(args);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
async function cmdDispatchTestFuzzerHandler(args: any) {
|
| 72 |
+
// Build the project
|
| 73 |
+
setStatusText('Test specific fuzzer: building fuzzers in workspace');
|
| 74 |
+
if (!(await buildFuzzersFromWorkspace(args.projectName, '', false))) {
|
| 75 |
+
println('Build projects');
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Run the fuzzer for 10 seconds
|
| 80 |
+
println('Running fuzzer');
|
| 81 |
+
setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
|
| 82 |
+
await runFuzzerHandler(
|
| 83 |
+
args.projectName,
|
| 84 |
+
args.fuzzerName,
|
| 85 |
+
extensionConfig.numberOfSecondsForTestRuns.toString(),
|
| 86 |
+
''
|
| 87 |
+
);
|
| 88 |
+
setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
|
| 89 |
+
return;
|
| 90 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {Uri} from 'vscode';
|
| 19 |
+
import {println} from './logger';
|
| 20 |
+
import {
|
| 21 |
+
getOSSFuzzCloudURL,
|
| 22 |
+
getLocalOutBuildDir,
|
| 23 |
+
downloadRemoteURL,
|
| 24 |
+
} from './utils';
|
| 25 |
+
|
| 26 |
+
const path = require('path');
|
| 27 |
+
let isCodeCoverageEnabled = false;
|
| 28 |
+
|
| 29 |
+
// create a decorator type that we use to decorate small numbers
|
| 30 |
+
const codeCoveredLineDecorationType =
|
| 31 |
+
vscode.window.createTextEditorDecorationType({
|
| 32 |
+
backgroundColor: '#184916',
|
| 33 |
+
overviewRulerColor: 'blue',
|
| 34 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 35 |
+
light: {
|
| 36 |
+
// this color will be used in light color themes
|
| 37 |
+
borderColor: 'darkblue',
|
| 38 |
+
},
|
| 39 |
+
dark: {
|
| 40 |
+
// this color will be used in dark color themes
|
| 41 |
+
borderColor: 'lightblue',
|
| 42 |
+
},
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
const missingLineDecorationType = vscode.window.createTextEditorDecorationType({
|
| 46 |
+
backgroundColor: '#6C2B34',
|
| 47 |
+
overviewRulerColor: 'blue',
|
| 48 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 49 |
+
light: {
|
| 50 |
+
// this color will be used in light color themes
|
| 51 |
+
borderColor: 'darkblue',
|
| 52 |
+
},
|
| 53 |
+
dark: {
|
| 54 |
+
// this color will be used in dark color themes
|
| 55 |
+
borderColor: 'lightblue',
|
| 56 |
+
},
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
export async function loadSummaryJsonCoverage(
|
| 60 |
+
context: vscode.ExtensionContext,
|
| 61 |
+
codeCoverageFile: Uri
|
| 62 |
+
) {
|
| 63 |
+
const coverageSummaryRawJson = await vscode.workspace.openTextDocument(
|
| 64 |
+
codeCoverageFile
|
| 65 |
+
);
|
| 66 |
+
const jsonCodeCoverage = JSON.parse(coverageSummaryRawJson.getText());
|
| 67 |
+
return jsonCodeCoverage;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export async function compareLocalToRemoteCoverage(
|
| 71 |
+
context: vscode.ExtensionContext,
|
| 72 |
+
projectName: string
|
| 73 |
+
) {
|
| 74 |
+
println('Checking the file matching');
|
| 75 |
+
/* Get the coverage from the remote server */
|
| 76 |
+
const urlString =
|
| 77 |
+
(await getOSSFuzzCloudURL(projectName)) + '/linux/summary.json';
|
| 78 |
+
|
| 79 |
+
println('URL: ' + urlString);
|
| 80 |
+
const codeCoverageFile: false | vscode.Uri = await downloadRemoteURL(
|
| 81 |
+
urlString,
|
| 82 |
+
'summary.json',
|
| 83 |
+
context
|
| 84 |
+
);
|
| 85 |
+
if (!codeCoverageFile) {
|
| 86 |
+
println('Could not get the coverage summary file');
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
const remoteCoverage = await loadSummaryJsonCoverage(
|
| 90 |
+
context,
|
| 91 |
+
codeCoverageFile
|
| 92 |
+
);
|
| 93 |
+
|
| 94 |
+
/* Get the local coverage report */
|
| 95 |
+
// Compare the local coverage to the upstream coverage
|
| 96 |
+
const localSummaryCovPath =
|
| 97 |
+
(await getLocalOutBuildDir(projectName)) + '/report/linux/summary.json';
|
| 98 |
+
const localCodeCoverage = await loadSummaryJsonCoverage(
|
| 99 |
+
context,
|
| 100 |
+
vscode.Uri.file(localSummaryCovPath)
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
for (let i = 0; i < localCodeCoverage.data[0].files.length; i++) {
|
| 104 |
+
for (let j = 0; j < remoteCoverage.data[0].files.length; j++) {
|
| 105 |
+
// Get the file dictionary
|
| 106 |
+
const localFileData = localCodeCoverage.data[0].files[i];
|
| 107 |
+
const remoteFileData = remoteCoverage.data[0].files[j];
|
| 108 |
+
|
| 109 |
+
// If the filepaths are the same, then we match coverage data
|
| 110 |
+
if (localFileData.filename === remoteFileData.filename) {
|
| 111 |
+
const remoteFuncCount = remoteFileData.summary.functions.count;
|
| 112 |
+
const localFuncCount = localFileData.summary.functions.count;
|
| 113 |
+
|
| 114 |
+
if (localFuncCount > remoteFuncCount) {
|
| 115 |
+
println(
|
| 116 |
+
'Coverage improved in :' +
|
| 117 |
+
localFileData.filename +
|
| 118 |
+
' [' +
|
| 119 |
+
localFuncCount +
|
| 120 |
+
' : ' +
|
| 121 |
+
remoteFuncCount +
|
| 122 |
+
']'
|
| 123 |
+
);
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
*
|
| 132 |
+
* @param context Adds visualisation to the editor based on reading a code coverage file.
|
| 133 |
+
* @param codeCoverageFile
|
| 134 |
+
*/
|
| 135 |
+
export async function loadCoverageIntoWorkspace(
|
| 136 |
+
context: vscode.ExtensionContext,
|
| 137 |
+
codeCoverageFile: Uri
|
| 138 |
+
) {
|
| 139 |
+
isCodeCoverageEnabled = true;
|
| 140 |
+
|
| 141 |
+
const doc3 = await vscode.workspace.openTextDocument(codeCoverageFile);
|
| 142 |
+
const jsonCodeCoverageObj3 = JSON.parse(doc3.getText());
|
| 143 |
+
|
| 144 |
+
const codeCoverageMappingWithCoverage = new Map();
|
| 145 |
+
const codeCoverageMapMissingCoverage = new Map();
|
| 146 |
+
|
| 147 |
+
Object.entries(jsonCodeCoverageObj3['files']).forEach(entry => {
|
| 148 |
+
const [key, value] = entry;
|
| 149 |
+
println(key);
|
| 150 |
+
const filename = path.parse(key).base;
|
| 151 |
+
println('Filename base: ' + filename);
|
| 152 |
+
const objectDictionary: any = value as any;
|
| 153 |
+
const linesWithCodeCoverage: unknown[] = [];
|
| 154 |
+
println(objectDictionary['executed_lines']);
|
| 155 |
+
Object.entries(objectDictionary['executed_lines']).forEach(entryInner => {
|
| 156 |
+
const lineNumber = entryInner[1];
|
| 157 |
+
//println("executed line: " + lineNumber);
|
| 158 |
+
linesWithCodeCoverage.push(lineNumber);
|
| 159 |
+
});
|
| 160 |
+
codeCoverageMappingWithCoverage.set(filename, linesWithCodeCoverage);
|
| 161 |
+
|
| 162 |
+
const linesMissingCodeCoverage: unknown[] = [];
|
| 163 |
+
Object.entries(objectDictionary['missing_lines']).forEach(entryInner => {
|
| 164 |
+
const lineNumber = entryInner[1];
|
| 165 |
+
//println("executed line: " + line_numb);
|
| 166 |
+
linesMissingCodeCoverage.push(lineNumber);
|
| 167 |
+
});
|
| 168 |
+
codeCoverageMapMissingCoverage.set(filename, linesMissingCodeCoverage);
|
| 169 |
+
});
|
| 170 |
+
println('=========>');
|
| 171 |
+
|
| 172 |
+
println('Enabling code coverage decorator');
|
| 173 |
+
println('decorator sample is activated');
|
| 174 |
+
|
| 175 |
+
let timeout: NodeJS.Timer | undefined = undefined;
|
| 176 |
+
|
| 177 |
+
// create a decorator type that we use to decorate large numbers
|
| 178 |
+
|
| 179 |
+
let activeEditor = vscode.window.activeTextEditor;
|
| 180 |
+
|
| 181 |
+
function updateDecorations(
|
| 182 |
+
linesWithCodeCoverage: any,
|
| 183 |
+
linesWithoNoCodeCoverage: any
|
| 184 |
+
) {
|
| 185 |
+
if (!isCodeCoverageEnabled) {
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
if (!activeEditor) {
|
| 189 |
+
return;
|
| 190 |
+
}
|
| 191 |
+
println('Filename');
|
| 192 |
+
println(activeEditor.document.fileName);
|
| 193 |
+
|
| 194 |
+
// Current file opened in the editor.
|
| 195 |
+
const nameOfCurrentFile = path.parse(activeEditor.document.fileName).base;
|
| 196 |
+
|
| 197 |
+
println('Base filename: ' + nameOfCurrentFile);
|
| 198 |
+
println('Done filename');
|
| 199 |
+
const lineNumbersWithCoverage: vscode.DecorationOptions[] = [];
|
| 200 |
+
const missingLineNumbers: vscode.DecorationOptions[] = [];
|
| 201 |
+
|
| 202 |
+
if (linesWithCodeCoverage.has(nameOfCurrentFile)) {
|
| 203 |
+
println('Has this file');
|
| 204 |
+
const elemWithCov = linesWithCodeCoverage.get(nameOfCurrentFile);
|
| 205 |
+
for (let idx = 0; idx < elemWithCov.length; idx++) {
|
| 206 |
+
const lineNo = elemWithCov[idx];
|
| 207 |
+
println('Setting up: ' + lineNo);
|
| 208 |
+
lineNumbersWithCoverage.push({
|
| 209 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 210 |
+
});
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
const elemNoCov = linesWithoNoCodeCoverage.get(nameOfCurrentFile);
|
| 214 |
+
for (let idx = 0; idx < elemNoCov.length; idx++) {
|
| 215 |
+
const lineNo = elemNoCov[idx];
|
| 216 |
+
println('Setting up: ' + lineNo);
|
| 217 |
+
missingLineNumbers.push({
|
| 218 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 219 |
+
});
|
| 220 |
+
}
|
| 221 |
+
} else {
|
| 222 |
+
println('Does not have this file');
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
activeEditor.setDecorations(
|
| 226 |
+
codeCoveredLineDecorationType,
|
| 227 |
+
lineNumbersWithCoverage
|
| 228 |
+
);
|
| 229 |
+
activeEditor.setDecorations(missingLineDecorationType, missingLineNumbers);
|
| 230 |
+
//activeEditor.setDecorations(largeNumberDecorationType, largeNumbers);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function triggerUpdateDecorations(
|
| 234 |
+
throttle = false,
|
| 235 |
+
covMap: any,
|
| 236 |
+
covMisMap: any
|
| 237 |
+
) {
|
| 238 |
+
if (timeout) {
|
| 239 |
+
clearTimeout(timeout);
|
| 240 |
+
timeout = undefined;
|
| 241 |
+
}
|
| 242 |
+
if (throttle) {
|
| 243 |
+
//timeout = setTimeout(updateDecorations, 500);
|
| 244 |
+
updateDecorations(covMap, covMisMap);
|
| 245 |
+
} else {
|
| 246 |
+
updateDecorations(covMap, covMisMap);
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if (activeEditor) {
|
| 251 |
+
triggerUpdateDecorations(
|
| 252 |
+
false,
|
| 253 |
+
codeCoverageMappingWithCoverage,
|
| 254 |
+
codeCoverageMapMissingCoverage
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
vscode.window.onDidChangeActiveTextEditor(
|
| 259 |
+
editor => {
|
| 260 |
+
activeEditor = editor;
|
| 261 |
+
if (editor) {
|
| 262 |
+
triggerUpdateDecorations(
|
| 263 |
+
false,
|
| 264 |
+
codeCoverageMappingWithCoverage,
|
| 265 |
+
codeCoverageMapMissingCoverage
|
| 266 |
+
);
|
| 267 |
+
}
|
| 268 |
+
},
|
| 269 |
+
null,
|
| 270 |
+
context.subscriptions
|
| 271 |
+
);
|
| 272 |
+
|
| 273 |
+
vscode.workspace.onDidChangeTextDocument(
|
| 274 |
+
event => {
|
| 275 |
+
if (activeEditor && event.document === activeEditor.document) {
|
| 276 |
+
triggerUpdateDecorations(
|
| 277 |
+
true,
|
| 278 |
+
codeCoverageMappingWithCoverage,
|
| 279 |
+
codeCoverageMapMissingCoverage
|
| 280 |
+
);
|
| 281 |
+
}
|
| 282 |
+
},
|
| 283 |
+
null,
|
| 284 |
+
context.subscriptions
|
| 285 |
+
);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* Removes the values from the mappings used to track code coverage. As a
|
| 290 |
+
* result, the visualisation disappears.
|
| 291 |
+
*/
|
| 292 |
+
export async function clearCoverage() {
|
| 293 |
+
// Set global indicator.
|
| 294 |
+
const activeEditor = vscode.window.activeTextEditor;
|
| 295 |
+
isCodeCoverageEnabled = false;
|
| 296 |
+
if (activeEditor) {
|
| 297 |
+
activeEditor.setDecorations(codeCoveredLineDecorationType, []);
|
| 298 |
+
activeEditor.setDecorations(missingLineDecorationType, []);
|
| 299 |
+
}
|
| 300 |
+
}
|
local-test-tika-delta-04/fuzz-tooling/tools/vscode-extension/src/ossfuzzWrappers.ts
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 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 |
+
const fs = require('fs');
|
| 18 |
+
import * as vscode from 'vscode';
|
| 19 |
+
import {
|
| 20 |
+
hasOssFuzzInWorkspace,
|
| 21 |
+
getOssFuzzWorkspaceProjectName,
|
| 22 |
+
listFuzzersForProject,
|
| 23 |
+
systemSyncLogIfFailure,
|
| 24 |
+
} from './utils';
|
| 25 |
+
import {println} from './logger';
|
| 26 |
+
import {extensionConfig} from './config';
|
| 27 |
+
|
| 28 |
+
export async function buildFuzzersFromWorkspaceClusterfuzzLite() {
|
| 29 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 30 |
+
if (!workspaceFolder) {
|
| 31 |
+
println('No workspace folder, exiting');
|
| 32 |
+
return false;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 36 |
+
const cmdToExec = 'python3';
|
| 37 |
+
const args = [
|
| 38 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 39 |
+
'build_fuzzers',
|
| 40 |
+
];
|
| 41 |
+
|
| 42 |
+
args.push('--external');
|
| 43 |
+
args.push(workspaceFolder[0].uri.path);
|
| 44 |
+
println('Building fuzzers');
|
| 45 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 46 |
+
println('Failed to build fuzzers');
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
return true;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Builds the fuzzers for a given workspace.
|
| 54 |
+
*
|
| 55 |
+
* There are two options:
|
| 56 |
+
* 1) The fuzzers are build using the OSS-Fuzz set up in the folder
|
| 57 |
+
* 2) The fuzzers are build using the workspace and then copies that over.
|
| 58 |
+
*/
|
| 59 |
+
export async function buildFuzzersFromWorkspace(
|
| 60 |
+
projectNameArg: string,
|
| 61 |
+
sanitizer: string,
|
| 62 |
+
toClean: boolean
|
| 63 |
+
) {
|
| 64 |
+
// println('Building fuzzers locally');
|
| 65 |
+
|
| 66 |
+
// Check if there is an OSS-Fuzz set up, and exit if not.
|
| 67 |
+
if (
|
| 68 |
+
(await isPathValidOssFuzzPath(
|
| 69 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 70 |
+
)) === false
|
| 71 |
+
) {
|
| 72 |
+
println('No valid oss-fuzz path');
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 77 |
+
if (!workspaceFolder) {
|
| 78 |
+
println('No workspace folder, exiting');
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
let ossFuzzProjectName = '';
|
| 83 |
+
if (await hasOssFuzzInWorkspace()) {
|
| 84 |
+
/**
|
| 85 |
+
* The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
|
| 86 |
+
*/
|
| 87 |
+
ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* The workspace has an OSS-Fuzz directory. We use this for the build.
|
| 91 |
+
* This is done by copying over the relevant files to the oss-fuzz repository
|
| 92 |
+
* folder. Notice that we will do a forceful copy overwriting the existing
|
| 93 |
+
* project foler if it exists.
|
| 94 |
+
*/
|
| 95 |
+
println('Found project folder: ' + ossFuzzProjectName);
|
| 96 |
+
|
| 97 |
+
// Copy over the workspace oss-fuzz set up to the oss-fuzz folder.
|
| 98 |
+
let cmdToExec = 'cp';
|
| 99 |
+
let args: Array<string> = [
|
| 100 |
+
'-rfT',
|
| 101 |
+
workspaceFolder[0].uri.path + '/OSS-Fuzz/' + ossFuzzProjectName,
|
| 102 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 103 |
+
'/projects/' +
|
| 104 |
+
ossFuzzProjectName +
|
| 105 |
+
'/',
|
| 106 |
+
];
|
| 107 |
+
|
| 108 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 109 |
+
println('Failed to copy project');
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 114 |
+
cmdToExec = 'python3';
|
| 115 |
+
args = [
|
| 116 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 117 |
+
'build_fuzzers',
|
| 118 |
+
];
|
| 119 |
+
println('DECIDING ABOUT SANITIZER');
|
| 120 |
+
if (sanitizer !== '') {
|
| 121 |
+
println('ADDING CODE COVERAGE SANITIZER');
|
| 122 |
+
args.push('--sanitizer=' + sanitizer);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
if (toClean) {
|
| 126 |
+
args.push('--clean');
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
args.push(ossFuzzProjectName);
|
| 130 |
+
println('Building fuzzers');
|
| 131 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 132 |
+
println('Failed to build fuzzers');
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
} else {
|
| 136 |
+
ossFuzzProjectName = projectNameArg;
|
| 137 |
+
|
| 138 |
+
const targetOssFuzzProject = vscode.Uri.file(
|
| 139 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 140 |
+
'/projects/' +
|
| 141 |
+
ossFuzzProjectName
|
| 142 |
+
);
|
| 143 |
+
// Check if the folder exists.
|
| 144 |
+
let projectHasOssFuzzFolder = false;
|
| 145 |
+
try {
|
| 146 |
+
await vscode.workspace.fs.readDirectory(targetOssFuzzProject);
|
| 147 |
+
projectHasOssFuzzFolder = true;
|
| 148 |
+
} catch {
|
| 149 |
+
projectHasOssFuzzFolder = false;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* The workspace does not have a OSS-Fuzz specific folder but has
|
| 154 |
+
* a folder in the OSS-Fuzz/projects/* directory. As such, we build
|
| 155 |
+
* the project using that build.sh set up, but, instead of cloning
|
| 156 |
+
* the repository we mount the workspace root onto what would normally
|
| 157 |
+
* be cloned.
|
| 158 |
+
*/
|
| 159 |
+
if (projectHasOssFuzzFolder) {
|
| 160 |
+
// println('Found a target directory');
|
| 161 |
+
|
| 162 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 163 |
+
// First, Set up a temporary workpath that will be cleanup after
|
| 164 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 165 |
+
const cmdToExec2 = 'cp';
|
| 166 |
+
const temporaryProjectPath =
|
| 167 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 168 |
+
'/projects/' +
|
| 169 |
+
ossFuzzProjectName +
|
| 170 |
+
'/temporary-project';
|
| 171 |
+
|
| 172 |
+
const args2: Array<string> = [
|
| 173 |
+
'-rfT',
|
| 174 |
+
wsPath.toString(),
|
| 175 |
+
temporaryProjectPath,
|
| 176 |
+
];
|
| 177 |
+
|
| 178 |
+
if (!(await systemSyncLogIfFailure(cmdToExec2, args2))) {
|
| 179 |
+
println('Failed to build fuzzers');
|
| 180 |
+
return false;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
//const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 184 |
+
const temporaryDockerPath =
|
| 185 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 186 |
+
'/projects/' +
|
| 187 |
+
ossFuzzProjectName +
|
| 188 |
+
'/Dockerfile';
|
| 189 |
+
const temporaryDockerPath2 =
|
| 190 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 191 |
+
'/projects/' +
|
| 192 |
+
ossFuzzProjectName +
|
| 193 |
+
'/Dockerfile2';
|
| 194 |
+
|
| 195 |
+
const args3: Array<string> = [temporaryDockerPath, temporaryDockerPath2];
|
| 196 |
+
if (!(await systemSyncLogIfFailure('cp', args3))) {
|
| 197 |
+
println('Failed to copy Dockerfile');
|
| 198 |
+
return false;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// Append COPY command to Dockerfile
|
| 202 |
+
fs.appendFileSync(
|
| 203 |
+
temporaryDockerPath,
|
| 204 |
+
'COPY temporary-project /src/' + ossFuzzProjectName
|
| 205 |
+
);
|
| 206 |
+
|
| 207 |
+
// Second, build the actual fuzzers using the temporarily created project path for mount.
|
| 208 |
+
const cmdToExec = 'python3';
|
| 209 |
+
const args = [
|
| 210 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 211 |
+
'build_fuzzers', // command
|
| 212 |
+
];
|
| 213 |
+
|
| 214 |
+
// Add sanitizer if needed.
|
| 215 |
+
if (sanitizer !== '') {
|
| 216 |
+
args.push('--sanitizer=' + sanitizer);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
// Add clean flag if needed.
|
| 220 |
+
if (toClean) {
|
| 221 |
+
args.push('--clean');
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
args.push(ossFuzzProjectName);
|
| 225 |
+
/*
|
| 226 |
+
Previously we used OSS-Fuzz logic that supports mounting paths for getting
|
| 227 |
+
the workspace into the Dockerfile.
|
| 228 |
+
This approach, however, has limitations in that most builds will modify
|
| 229 |
+
the contents of the folder they're working in. This can cause issues and also
|
| 230 |
+
make it not possible to build several versions of the project with changing
|
| 231 |
+
sanitizers in a sequence. As such, we disbanded.
|
| 232 |
+
*/
|
| 233 |
+
println('Building fuzzers');
|
| 234 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 235 |
+
println('Failed to copy Dockerfile');
|
| 236 |
+
// Move back the modified Dockerfile
|
| 237 |
+
const args5: Array<string> = [
|
| 238 |
+
temporaryDockerPath2,
|
| 239 |
+
temporaryDockerPath,
|
| 240 |
+
];
|
| 241 |
+
if (!(await systemSyncLogIfFailure('mv', args5))) {
|
| 242 |
+
println('Failed to copy back Dockerfile');
|
| 243 |
+
return false;
|
| 244 |
+
}
|
| 245 |
+
return false;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// Move back the modified Dockerfile
|
| 249 |
+
const args5: Array<string> = [temporaryDockerPath2, temporaryDockerPath];
|
| 250 |
+
if (!(await systemSyncLogIfFailure('mv', args5))) {
|
| 251 |
+
println('Failed to copy back Dockerfile');
|
| 252 |
+
return false;
|
| 253 |
+
}
|
| 254 |
+
} else {
|
| 255 |
+
println('OSS-Fuzz does not have the relevant project folder');
|
| 256 |
+
return false;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// If we go to here we successfully build the project. Give information.
|
| 261 |
+
vscode.window.showInformationMessage('Successfully build project');
|
| 262 |
+
|
| 263 |
+
// List the fuzzers build
|
| 264 |
+
await listFuzzersForProject(
|
| 265 |
+
ossFuzzProjectName,
|
| 266 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 267 |
+
);
|
| 268 |
+
return true;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/**
|
| 272 |
+
* Runs the fuzzer for a given CFLite project
|
| 273 |
+
*/
|
| 274 |
+
export async function runFuzzerHandlerCFLite(
|
| 275 |
+
projectNameArg: string,
|
| 276 |
+
fuzzerNameArg: string,
|
| 277 |
+
secondsToRunArg: string
|
| 278 |
+
) {
|
| 279 |
+
// The fuzzer is run by way of OSS-Fuzz's helper.py so we use python3 to launch
|
| 280 |
+
// this script.
|
| 281 |
+
const cmdToExec = 'python3';
|
| 282 |
+
|
| 283 |
+
// Set the arguments correctly. The ordering here is important for compatibility
|
| 284 |
+
// with the underlying argparse used by OSS-Fuzz helper.py.
|
| 285 |
+
const args: Array<string> = [
|
| 286 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 287 |
+
'run_fuzzer',
|
| 288 |
+
];
|
| 289 |
+
|
| 290 |
+
args.push('--external');
|
| 291 |
+
args.push(projectNameArg);
|
| 292 |
+
args.push(fuzzerNameArg);
|
| 293 |
+
args.push('--');
|
| 294 |
+
args.push('-max_total_time=' + secondsToRunArg);
|
| 295 |
+
|
| 296 |
+
println(
|
| 297 |
+
'Running fuzzer' +
|
| 298 |
+
fuzzerNameArg +
|
| 299 |
+
' from project ' +
|
| 300 |
+
projectNameArg +
|
| 301 |
+
' for ' +
|
| 302 |
+
secondsToRunArg +
|
| 303 |
+
' seconds.'
|
| 304 |
+
);
|
| 305 |
+
|
| 306 |
+
// Run the actual command
|
| 307 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 308 |
+
println('Failed to run fuzzer');
|
| 309 |
+
return false;
|
| 310 |
+
}
|
| 311 |
+
return true;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
/**
|
| 315 |
+
* Runs the fuzzer for a given project.
|
| 316 |
+
*/
|
| 317 |
+
export async function runFuzzerHandler(
|
| 318 |
+
projectNameArg: string,
|
| 319 |
+
fuzzerNameArg: string,
|
| 320 |
+
secondsToRunArg: string,
|
| 321 |
+
fuzzerCorpusPath: string
|
| 322 |
+
) {
|
| 323 |
+
// Check there is a valid OSS-Fuzz path. If not, bail out.
|
| 324 |
+
if (
|
| 325 |
+
(await isPathValidOssFuzzPath(
|
| 326 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 327 |
+
)) === false
|
| 328 |
+
) {
|
| 329 |
+
println('Missing valid OSS-Fuzz path.');
|
| 330 |
+
return;
|
| 331 |
+
}
|
| 332 |
+
// The fuzzer is run by way of OSS-Fuzz's helper.py so we use python3 to launch
|
| 333 |
+
// this script.
|
| 334 |
+
const cmdToExec = 'python3';
|
| 335 |
+
|
| 336 |
+
// Set the arguments correctly. The ordering here is important for compatibility
|
| 337 |
+
// with the underlying argparse used by OSS-Fuzz helper.py.
|
| 338 |
+
const args: Array<string> = [
|
| 339 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 340 |
+
'run_fuzzer',
|
| 341 |
+
];
|
| 342 |
+
if (fuzzerCorpusPath !== '') {
|
| 343 |
+
args.push('--corpus-dir');
|
| 344 |
+
args.push(fuzzerCorpusPath);
|
| 345 |
+
}
|
| 346 |
+
args.push(projectNameArg);
|
| 347 |
+
args.push(fuzzerNameArg);
|
| 348 |
+
args.push('--');
|
| 349 |
+
args.push('-max_total_time=' + secondsToRunArg);
|
| 350 |
+
|
| 351 |
+
println(
|
| 352 |
+
'Running fuzzer' +
|
| 353 |
+
fuzzerNameArg +
|
| 354 |
+
' from project ' +
|
| 355 |
+
projectNameArg +
|
| 356 |
+
' for ' +
|
| 357 |
+
secondsToRunArg +
|
| 358 |
+
' seconds.'
|
| 359 |
+
);
|
| 360 |
+
|
| 361 |
+
// Run the actual command
|
| 362 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 363 |
+
println('Failed to run fuzzer');
|
| 364 |
+
return false;
|
| 365 |
+
}
|
| 366 |
+
return true;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// Validates if a directory is a valid oss-fuzz path.
|
| 370 |
+
export async function isPathValidOssFuzzPath(path: string) {
|
| 371 |
+
try {
|
| 372 |
+
if (await vscode.workspace.fs.readDirectory(vscode.Uri.file(path))) {
|
| 373 |
+
// println('Is a directory');
|
| 374 |
+
// const helperPath = vscode.Uri.file(path + '/infra/helper.py');
|
| 375 |
+
const helperPath = path + '/infra/helper.py';
|
| 376 |
+
//console.log('Checking ' + helperPath.toString());
|
| 377 |
+
if (fs.existsSync(helperPath.toString())) {
|
| 378 |
+
return true;
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
} catch {
|
| 382 |
+
/* empty */
|
| 383 |
+
}
|
| 384 |
+
return false;
|
| 385 |
+
}
|