Kitxuuu commited on
Commit
f8e4e4f
·
verified ·
1 Parent(s): 9391520

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-commons-compress-delta-02/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc +0 -0
  2. local-test-commons-compress-delta-02/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc +0 -0
  3. local-test-commons-compress-delta-02/fuzz-tooling/infra/base-images/README.md +6 -0
  4. local-test-commons-compress-delta-02/fuzz-tooling/infra/base-images/all.sh +28 -0
  5. local-test-commons-compress-delta-02/fuzz-tooling/infra/ci/build_test.py +124 -0
  6. local-test-commons-compress-delta-02/fuzz-tooling/infra/ci/requirements.txt +9 -0
  7. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/CHANGELOG +3 -0
  8. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/affected_fuzz_targets.py +113 -0
  9. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/build-images.sh +34 -0
  10. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/continuous_integration.py +375 -0
  11. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/http_utils_test.py +71 -0
  12. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/requirements.txt +4 -0
  13. local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/run_cifuzz.py +89 -0
  14. local-test-commons-compress-delta-02/fuzz-tooling/infra/tools/hold_back_images.py +128 -0
  15. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts +80 -0
  16. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts +192 -0
  17. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
  18. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts +24 -0
  19. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts +59 -0
  20. local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts +24 -0
local-test-commons-compress-delta-02/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc ADDED
Binary file (802 Bytes). View file
 
local-test-commons-compress-delta-02/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc ADDED
Binary file (3.04 kB). View file
 
local-test-commons-compress-delta-02/fuzz-tooling/infra/base-images/README.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Building all infra images:
2
+
3
+ ```bash
4
+ # run from project root
5
+ infra/base-images/all.sh
6
+ ```
local-test-commons-compress-delta-02/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-commons-compress-delta-02/fuzz-tooling/infra/ci/build_test.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+ """Tests for build.py"""
17
+
18
+ import os
19
+ import sys
20
+ import unittest
21
+ from unittest import mock
22
+
23
+ # pylint: disable=wrong-import-position
24
+ INFRA_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25
+ sys.path.append(INFRA_DIR)
26
+
27
+ from ci import build
28
+
29
+
30
+ def patch_environ(testcase_obj):
31
+ """Patch environment."""
32
+ env = {}
33
+ patcher = mock.patch.dict(os.environ, env)
34
+ testcase_obj.addCleanup(patcher.stop)
35
+ patcher.start()
36
+
37
+
38
+ def _set_coverage_build():
39
+ """Set the right environment variables for a coverage build."""
40
+ os.environ['SANITIZER'] = 'coverage'
41
+ os.environ['ENGINE'] = 'libfuzzer'
42
+ os.environ['ARCHITECTURE'] = 'x86_64'
43
+
44
+
45
+ class TestShouldBuild(unittest.TestCase):
46
+ """Tests that should_build() works as intended."""
47
+
48
+ def setUp(self):
49
+ patch_environ(self)
50
+
51
+ def test_none_engine_coverage_build(self):
52
+ """Tests that should_build returns False for a coverage build of a
53
+ project that specifies 'none' for fuzzing_engines."""
54
+ _set_coverage_build()
55
+ project_yaml = {
56
+ 'language': 'c++',
57
+ 'fuzzing_engines': ['none'],
58
+ 'sanitizers': ['address']
59
+ }
60
+ self.assertFalse(build.should_build(project_yaml))
61
+
62
+ def test_unspecified_engines_coverage_build(self):
63
+ """Tests that should_build returns True for a coverage build of a
64
+ project that doesn't specify fuzzing_engines."""
65
+ _set_coverage_build()
66
+ project_yaml = {'language': 'c++'}
67
+ self.assertTrue(build.should_build(project_yaml))
68
+
69
+ def test_libfuzzer_coverage_build(self):
70
+ """Tests that should_build returns True for coverage build of a project
71
+ specifying 'libfuzzer' for fuzzing_engines."""
72
+ _set_coverage_build()
73
+ project_yaml = {
74
+ 'language': 'c++',
75
+ 'fuzzing_engines': ['libfuzzer'],
76
+ 'sanitizers': ['address']
77
+ }
78
+ self.assertTrue(build.should_build(project_yaml))
79
+
80
+ def test_go_coverage_build(self):
81
+ """Tests that should_build returns True for coverage build of a project
82
+ specifying 'libfuzzer' for fuzzing_engines."""
83
+ _set_coverage_build()
84
+ project_yaml = {'language': 'go'}
85
+ self.assertTrue(build.should_build(project_yaml))
86
+
87
+ def test_engine_project_none_build(self):
88
+ """Tests that should_build returns False for an engine: 'none' build when
89
+ the project doesn't specify engines."""
90
+ os.environ['SANITIZER'] = 'address'
91
+ os.environ['ENGINE'] = 'none'
92
+ os.environ['ARCHITECTURE'] = 'x86_64'
93
+ project_yaml = {
94
+ 'language': 'c++',
95
+ 'fuzzing_engines': ['libfuzzer'],
96
+ 'sanitizers': ['address']
97
+ }
98
+ self.assertFalse(build.should_build(project_yaml))
99
+
100
+ def test_centipede_none_build(self):
101
+ """Tests that should_build returns True for none sanitizer build of a
102
+ project specifying 'centipede' for fuzzing_engines."""
103
+ os.environ['SANITIZER'] = 'none'
104
+ os.environ['ENGINE'] = 'centipede'
105
+ os.environ['ARCHITECTURE'] = 'x86_64'
106
+ project_yaml = {
107
+ 'language': 'c++',
108
+ 'fuzzing_engines': ['centipede'],
109
+ 'sanitizers': ['none']
110
+ }
111
+ self.assertTrue(build.should_build(project_yaml))
112
+
113
+ def test_centipede_address_build(self):
114
+ """Tests that should_build returns True for address sanitizer build of a
115
+ project specifying 'centipede' for fuzzing_engines."""
116
+ os.environ['SANITIZER'] = 'address'
117
+ os.environ['ENGINE'] = 'centipede'
118
+ os.environ['ARCHITECTURE'] = 'x86_64'
119
+ project_yaml = {
120
+ 'language': 'c++',
121
+ 'fuzzing_engines': ['centipede'],
122
+ 'sanitizers': ['address']
123
+ }
124
+ self.assertTrue(build.should_build(project_yaml))
local-test-commons-compress-delta-02/fuzz-tooling/infra/ci/requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Requirements for submitting code changes to infra/ (needed by presubmit.py).
2
+ parameterized==0.7.4
3
+ pyfakefs==4.5.6
4
+ pylint==2.5.3
5
+ pytest==7.1.2
6
+ pytest-xdist==2.5.0
7
+ PyYAML==6.0
8
+ requests==2.31.0
9
+ yapf==0.32.0
local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/CHANGELOG ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Next Release:
2
+
3
+ Improve detection of changed files better by fixing https://github.com/google/oss-fuzz/issues/7011
local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/affected_fuzz_targets.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Module for dealing with fuzz targets affected by the change-under-test
15
+ (CUT)."""
16
+ import logging
17
+ import os
18
+ import sys
19
+
20
+ # pylint: disable=wrong-import-position,import-error
21
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
22
+ import utils
23
+
24
+
25
+ def remove_unaffected_fuzz_targets(clusterfuzz_deployment, out_dir,
26
+ files_changed, repo_path):
27
+ """Removes all non affected fuzz targets in the out directory.
28
+
29
+ Args:
30
+ clusterfuzz_deployment: The ClusterFuzz deployment object.
31
+ out_dir: The location of the fuzz target binaries.
32
+ files_changed: A list of files changed compared to HEAD.
33
+ repo_path: The location of the OSS-Fuzz repo in the docker image.
34
+
35
+ This function will not delete fuzz targets unless it knows that the fuzz
36
+ targets are unaffected. For example, this means that fuzz targets which don't
37
+ have coverage data on will not be deleted.
38
+ """
39
+ if not files_changed:
40
+ # Don't remove any fuzz targets if there is no difference from HEAD.
41
+ logging.info('No files changed compared to HEAD.')
42
+ return
43
+
44
+ logging.info('Files changed in PR: %s', files_changed)
45
+
46
+ fuzz_target_paths = utils.get_fuzz_targets(out_dir)
47
+ if not fuzz_target_paths:
48
+ # Nothing to remove.
49
+ logging.error('No fuzz targets found in out dir.')
50
+ return
51
+
52
+ coverage = clusterfuzz_deployment.get_coverage(repo_path)
53
+ if not coverage:
54
+ # Don't remove any fuzz targets unless we have data.
55
+ logging.error('Could not find latest coverage report.')
56
+ return
57
+
58
+ affected_fuzz_targets = get_affected_fuzz_targets(coverage, fuzz_target_paths,
59
+ files_changed)
60
+
61
+ if not affected_fuzz_targets:
62
+ logging.info('No affected fuzz targets detected, keeping all as fallback.')
63
+ return
64
+
65
+ logging.info('Using affected fuzz targets: %s.', affected_fuzz_targets)
66
+ unaffected_fuzz_targets = set(fuzz_target_paths) - affected_fuzz_targets
67
+ logging.info('Removing unaffected fuzz targets: %s.', unaffected_fuzz_targets)
68
+
69
+ # Remove all the targets that are not affected.
70
+ for fuzz_target_path in unaffected_fuzz_targets:
71
+ try:
72
+ os.remove(fuzz_target_path)
73
+ except OSError as error:
74
+ logging.error('%s occurred while removing file %s', error,
75
+ fuzz_target_path)
76
+
77
+
78
+ def is_fuzz_target_affected(coverage, fuzz_target_path, files_changed):
79
+ """Returns True if a fuzz target (|fuzz_target_path|) is affected by
80
+ |files_changed|."""
81
+ fuzz_target = os.path.basename(fuzz_target_path)
82
+ covered_files = coverage.get_files_covered_by_target(fuzz_target)
83
+ if not covered_files:
84
+ # Assume a fuzz target is affected if we can't get its coverage from
85
+ # OSS-Fuzz.
86
+ # TODO(metzman): Figure out what we should do if covered_files is [].
87
+ # Should we act as if we couldn't get the coverage?
88
+ logging.info('Could not get coverage for %s. Treating as affected.',
89
+ fuzz_target)
90
+ return True
91
+
92
+ covered_files = [
93
+ os.path.normpath(covered_file) for covered_file in covered_files
94
+ ]
95
+ logging.info('Fuzz target %s is affected by: %s', fuzz_target, covered_files)
96
+ for filename in files_changed:
97
+ if filename in covered_files:
98
+ logging.info('Fuzz target %s is affected by changed file: %s',
99
+ fuzz_target, filename)
100
+ return True
101
+
102
+ logging.info('Fuzz target %s is not affected.', fuzz_target)
103
+ return False
104
+
105
+
106
+ def get_affected_fuzz_targets(coverage, fuzz_target_paths, files_changed):
107
+ """Returns a list of paths of affected targets."""
108
+ affected_fuzz_targets = set()
109
+ for fuzz_target_path in fuzz_target_paths:
110
+ if is_fuzz_target_affected(coverage, fuzz_target_path, files_changed):
111
+ affected_fuzz_targets.add(fuzz_target_path)
112
+
113
+ return affected_fuzz_targets
local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/build-images.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash -eux
2
+ # Copyright 2021 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Script for building the docker images for cifuzz.
17
+
18
+ CIFUZZ_DIR=$(dirname "$0")
19
+ CIFUZZ_DIR=$(realpath $CIFUZZ_DIR)
20
+ INFRA_DIR=$(realpath $CIFUZZ_DIR/..)
21
+ OSS_FUZZ_ROOT=$(realpath $INFRA_DIR/..)
22
+
23
+ # Build cifuzz-base.
24
+ docker build --tag ghcr.io/aixcc-finals/cifuzz-base --file $CIFUZZ_DIR/cifuzz-base/Dockerfile $OSS_FUZZ_ROOT
25
+
26
+ # Build run-fuzzers and build-fuzzers images.
27
+ docker build \
28
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers-test:v1 \
29
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers:v1 \
30
+ --file $INFRA_DIR/build_fuzzers.Dockerfile $INFRA_DIR
31
+ docker build \
32
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers:v1 \
33
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers-test:v1 \
34
+ --file $INFRA_DIR/run_fuzzers.Dockerfile $INFRA_DIR
local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/continuous_integration.py ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Implementations for various CI systems."""
15
+
16
+ import os
17
+ import collections
18
+ import sys
19
+ import logging
20
+
21
+ # pylint: disable=wrong-import-position,import-error
22
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
23
+ import build_specified_commit
24
+ import docker
25
+ import helper
26
+ import repo_manager
27
+ import retry
28
+ import utils
29
+ import workspace_utils
30
+
31
+ # pylint: disable=too-few-public-methods
32
+
33
+ BuildPreparationResult = collections.namedtuple(
34
+ 'BuildPreparationResult', ['success', 'image_repo_path', 'repo_manager'])
35
+
36
+ _IMAGE_BUILD_TRIES = 3
37
+ _IMAGE_BUILD_BACKOFF = 2
38
+
39
+
40
+ def fix_git_repo_for_diff(repo_manager_obj):
41
+ """Fixes git repos cloned by the "checkout" action so that diffing works on
42
+ them."""
43
+ command = [
44
+ 'git', 'symbolic-ref', 'refs/remotes/origin/HEAD',
45
+ 'refs/remotes/origin/master'
46
+ ]
47
+ return utils.execute(command, location=repo_manager_obj.repo_dir)
48
+
49
+
50
+ class BaseCi:
51
+ """Class representing common CI functionality."""
52
+
53
+ def __init__(self, config):
54
+ self.config = config
55
+ self.workspace = workspace_utils.Workspace(config)
56
+ self._repo_dir = None
57
+
58
+ @property
59
+ def repo_dir(self):
60
+ """Returns the source repo path, if it has been checked out. None is
61
+ returned otherwise."""
62
+ raise NotImplementedError('Child class must implement method.')
63
+
64
+ def prepare_for_fuzzer_build(self):
65
+ """Builds the fuzzer builder image and gets the source code we need to
66
+ fuzz."""
67
+ raise NotImplementedError('Child class must implement method.')
68
+
69
+ def get_diff_base(self):
70
+ """Returns the base to diff against with git to get the change under
71
+ test."""
72
+ if self.config.base_ref:
73
+ logging.debug('Diffing against base_ref: %s.', self.config.base_ref)
74
+ return self.config.base_ref
75
+ if self.config.base_commit:
76
+ logging.debug('Diffing against base_commit: %s.', self.config.base_commit)
77
+ return self.config.base_commit
78
+ # TODO(metzman): Do we want this at all? What purpose does it serve? I guess
79
+ # it is a decent fallback when there is no base_commit or base_ref.
80
+ logging.debug('Diffing against origin.')
81
+ return 'origin'
82
+
83
+ def get_changed_code_under_test(self, repo_manager_obj):
84
+ """Returns the changed files that need to be tested."""
85
+ if self.config.base_ref:
86
+ repo_manager_obj.fetch_branch(self.config.base_ref)
87
+ fix_git_repo_for_diff(repo_manager_obj)
88
+ base = self.get_diff_base()
89
+ logging.info('Diffing against %s.', base)
90
+ # git diff <commit>... is equivalent to
91
+ # git diff $(git merge-base <commit> HEAD)
92
+ return repo_manager_obj.get_git_diff(base + '...')
93
+
94
+ def get_build_command(self, host_repo_path, image_repo_path):
95
+ """Returns the command for building the project that is run inside the
96
+ project builder container."""
97
+ raise NotImplementedError('Child class must implement method.')
98
+
99
+ def _build_external_project_docker_image(self, manager):
100
+ """Helper for child classes that builds an external project's docker image.
101
+ Returns a BuildPreparationResult indicating failure or success."""
102
+ build_integration_abs_path = os.path.join(
103
+ manager.repo_dir, self.config.build_integration_path)
104
+ if not build_external_project_docker_image(manager.repo_dir,
105
+ build_integration_abs_path):
106
+ logging.error('Failed to build external project.')
107
+ return get_build_preparation_failure()
108
+ image_repo_path = os.path.join('/src', self.config.project_repo_name)
109
+ return BuildPreparationResult(success=True,
110
+ image_repo_path=image_repo_path,
111
+ repo_manager=manager)
112
+
113
+ def _make_repo_storage_dir(self):
114
+ os.makedirs(self.workspace.repo_storage, exist_ok=True)
115
+
116
+ def _clone_repo_and_checkout(self, repo_url, repo_name):
117
+ """Helper for child classes that clones the git repo specified by |repo_url|
118
+ to |repo_name|, checks out the specified commit, and returns the
119
+ |manager|."""
120
+ self._make_repo_storage_dir()
121
+ # Checkout project's repo in the shared volume.
122
+ manager = repo_manager.clone_repo_and_get_manager(
123
+ repo_url,
124
+ self.workspace.repo_storage,
125
+ repo_name=repo_name,
126
+ username=self.config.actor,
127
+ password=self.config.token)
128
+ self._checkout_specified_commit(manager)
129
+ return manager
130
+
131
+ def _checkout_specified_commit(self, manager):
132
+ checkout_specified_commit(manager, self.config.pr_ref, self.config.git_sha)
133
+
134
+ def _detect_main_repo(self):
135
+ """Helper for child classes that detects the main repo and returns a tuple
136
+ containing the inffered url and path to the repo in the image."""
137
+ inferred_url, image_repo_path = build_specified_commit.detect_main_repo(
138
+ self.config.oss_fuzz_project_name,
139
+ repo_name=self.config.project_repo_name)
140
+ if not inferred_url or not image_repo_path:
141
+ logging.error('Could not detect repo.')
142
+ return inferred_url, image_repo_path
143
+
144
+ def _create_repo_manager_for_project_src_path(self):
145
+ """Returns a repo manager for |project_src_path|."""
146
+ return repo_manager.RepoManager(self.config.project_src_path)
147
+
148
+
149
+ def get_build_command():
150
+ """Returns the command to build the project inside the project builder
151
+ container."""
152
+ return 'compile'
153
+
154
+
155
+ def get_replace_repo_and_build_command(host_repo_path, image_repo_path):
156
+ """Returns the command to replace the repo located at |image_repo_path| with
157
+ |host_repo_path| and build the project inside the project builder
158
+ container."""
159
+ rm_path = os.path.join(image_repo_path, '*')
160
+ image_src_path = os.path.dirname(image_repo_path)
161
+ build_command = get_build_command()
162
+ command = (f'cd / && rm -rf {rm_path} && cp -r {host_repo_path} '
163
+ f'{image_src_path} && cd - && {build_command}')
164
+ return command
165
+
166
+
167
+ def get_ci(config):
168
+ """Determines what kind of CI is being used and returns the object
169
+ representing that system."""
170
+
171
+ if config.platform == config.Platform.EXTERNAL_GENERIC_CI:
172
+ # Non-OSS-Fuzz projects must bring their own source and their own build
173
+ # integration (which is relative to that source).
174
+ return ExternalGeneric(config)
175
+ if config.platform == config.Platform.EXTERNAL_GITHUB:
176
+ # Non-OSS-Fuzz projects must bring their own source and their own build
177
+ # integration (which is relative to that source).
178
+ return ExternalGithub(config)
179
+
180
+ if config.platform == config.Platform.INTERNAL_GENERIC_CI:
181
+ # Builds of OSS-Fuzz projects not hosted on Github must bring their own
182
+ # source since the checkout logic CIFuzz implements is github-specific.
183
+ # TODO(metzman): Consider moving Github-actions builds of OSS-Fuzz projects
184
+ # to this system to reduce implementation complexity.
185
+ return InternalGeneric(config)
186
+
187
+ return InternalGithub(config)
188
+
189
+
190
+ def checkout_specified_commit(repo_manager_obj, pr_ref, git_sha):
191
+ """Checks out the specified commit or pull request using
192
+ |repo_manager_obj|."""
193
+ try:
194
+ if pr_ref:
195
+ repo_manager_obj.checkout_pr(pr_ref)
196
+ else:
197
+ repo_manager_obj.checkout_commit(git_sha)
198
+ except (RuntimeError, ValueError):
199
+ logging.error(
200
+ 'Can not check out requested state %s. '
201
+ 'Using current repo state.', pr_ref or git_sha)
202
+
203
+
204
+ class GithubCiMixin:
205
+ """Mixin for Github based CI systems."""
206
+
207
+ def __init__(self, config):
208
+ super().__init__(config)
209
+ # Unlike in other classes, here _repo_dir is the parent directory of the
210
+ # repo, not its actual directory.
211
+ self._repo_dir = self.workspace.repo_storage
212
+
213
+ @property
214
+ def repo_dir(self):
215
+ """Returns the source repo path, if it has been checked out. None is
216
+ returned otherwise."""
217
+ if not os.path.exists(self._repo_dir):
218
+ logging.warning('Repo dir: %s does not exist.', self._repo_dir)
219
+ return None
220
+
221
+ # Note: this assumes there is only one repo checked out here.
222
+ listing = os.listdir(self._repo_dir)
223
+ if len(listing) != 1:
224
+ raise RuntimeError('Invalid repo directory.')
225
+
226
+ repo_path = os.path.join(self._repo_dir, listing[0])
227
+ if not os.path.isdir(repo_path):
228
+ raise RuntimeError('Repo is not a directory.')
229
+
230
+ return repo_path
231
+
232
+
233
+ class InternalGithub(GithubCiMixin, BaseCi):
234
+ """Class representing CI for an OSS-Fuzz project on Github Actions."""
235
+
236
+ def _copy_repo_from_image(self, image_repo_path):
237
+ self._make_repo_storage_dir()
238
+ repo_name = os.path.basename(image_repo_path)
239
+ host_repo_path = os.path.join(self._repo_dir, repo_name)
240
+ bash_command = f'cp -r {image_repo_path} {host_repo_path}'
241
+ docker_args, _ = docker.get_base_docker_run_args(
242
+ self.workspace, self.config.sanitizer, self.config.language,
243
+ self.config.architecture, self.config.docker_in_docker)
244
+ docker_args.extend([
245
+ docker.get_project_image_name(self.config.oss_fuzz_project_name),
246
+ '/bin/bash', '-c', bash_command
247
+ ])
248
+ if not helper.docker_run(docker_args):
249
+ raise RuntimeError('Failed to copy repo.')
250
+ return repo_manager.RepoManager(host_repo_path)
251
+
252
+ def prepare_for_fuzzer_build(self):
253
+ """Builds the fuzzer builder image, checks out the pull request/commit and
254
+ returns the BuildPreparationResult."""
255
+ logging.info('InternalGithub: preparing for fuzzer build.')
256
+ assert self.config.pr_ref or self.config.git_sha
257
+ # _detect_main_repo builds the image as a side effect.
258
+ _, image_repo_path = self._detect_main_repo()
259
+ if not image_repo_path:
260
+ return get_build_preparation_failure()
261
+
262
+ # Use the same name used in the docker image so we can overwrite it.
263
+ manager = self._copy_repo_from_image(image_repo_path)
264
+ self._checkout_specified_commit(manager)
265
+ return BuildPreparationResult(success=True,
266
+ image_repo_path=image_repo_path,
267
+ repo_manager=manager)
268
+
269
+ def get_build_command(self, host_repo_path, image_repo_path): # pylint: disable=no-self-use
270
+ """Returns the command for building the project that is run inside the
271
+ project builder container. Command also replaces |image_repo_path| with
272
+ |host_repo_path|."""
273
+ return get_replace_repo_and_build_command(host_repo_path, image_repo_path)
274
+
275
+
276
+ def get_build_preparation_failure():
277
+ """Returns a BuildPreparationResult indicating failure."""
278
+ return BuildPreparationResult(success=False,
279
+ image_repo_path=None,
280
+ repo_manager=None)
281
+
282
+
283
+ class InternalGeneric(BaseCi):
284
+ """Class representing CI for an OSS-Fuzz project on a CI other than Github
285
+ actions."""
286
+
287
+ def __init__(self, config):
288
+ super().__init__(config)
289
+ self._repo_dir = config.project_src_path
290
+
291
+ @property
292
+ def repo_dir(self):
293
+ """Returns the source repo path, if it has been checked out. None is
294
+ returned otherwise."""
295
+ return self._repo_dir
296
+
297
+ def prepare_for_fuzzer_build(self):
298
+ """Builds the project builder image for an OSS-Fuzz project outside of
299
+ GitHub actions. Returns the repo_manager. Does not checkout source code
300
+ since external projects are expected to bring their own source code to
301
+ CIFuzz."""
302
+ logging.info('InternalGeneric: preparing for fuzzer build.')
303
+ # detect_main_repo builds the image as a side effect.
304
+ _, image_repo_path = self._detect_main_repo()
305
+
306
+ if not image_repo_path:
307
+ return get_build_preparation_failure()
308
+
309
+ manager = self._create_repo_manager_for_project_src_path()
310
+ return BuildPreparationResult(success=True,
311
+ image_repo_path=image_repo_path,
312
+ repo_manager=manager)
313
+
314
+ def get_build_command(self, host_repo_path, image_repo_path): # pylint: disable=no-self-use
315
+ """Returns the command for building the project that is run inside the
316
+ project builder container. Command also replaces |image_repo_path| with
317
+ |host_repo_path|."""
318
+ return get_replace_repo_and_build_command(host_repo_path, image_repo_path)
319
+
320
+
321
+ @retry.wrap(_IMAGE_BUILD_TRIES, _IMAGE_BUILD_BACKOFF)
322
+ def build_external_project_docker_image(project_src, build_integration_path):
323
+ """Builds the project builder image for an external (non-OSS-Fuzz) project.
324
+ Returns True on success."""
325
+ dockerfile_path = os.path.join(build_integration_path, 'Dockerfile')
326
+ command = [
327
+ '-t', docker.EXTERNAL_PROJECT_IMAGE, '-f', dockerfile_path, project_src
328
+ ]
329
+ return helper.docker_build(command)
330
+
331
+
332
+ class ExternalGeneric(BaseCi):
333
+ """CI implementation for generic CI for external (non-OSS-Fuzz) projects."""
334
+
335
+ def __init__(self, config):
336
+ super().__init__(config)
337
+ self._repo_dir = config.project_src_path
338
+
339
+ @property
340
+ def repo_dir(self):
341
+ """Returns the source repo path, if it has been checked out. None is
342
+ returned otherwise."""
343
+ return self._repo_dir
344
+
345
+ def prepare_for_fuzzer_build(self):
346
+ logging.info('ExternalGeneric: preparing for fuzzer build.')
347
+ manager = self._create_repo_manager_for_project_src_path()
348
+ return self._build_external_project_docker_image(manager)
349
+
350
+ def get_build_command(self, host_repo_path, image_repo_path): # pylint: disable=no-self-use
351
+ """Returns the command for building the project that is run inside the
352
+ project builder container."""
353
+ return get_build_command()
354
+
355
+
356
+ class ExternalGithub(GithubCiMixin, BaseCi):
357
+ """Class representing CI for a non-OSS-Fuzz project on Github Actions."""
358
+
359
+ def prepare_for_fuzzer_build(self):
360
+ """Builds the project builder image for a non-OSS-Fuzz project on GitHub
361
+ actions. Sets the repo manager. Does not checkout source code since external
362
+ projects are expected to bring their own source code to CIFuzz. Returns True
363
+ on success."""
364
+ logging.info('ExternalGithub: preparing for fuzzer build.')
365
+ # Checkout before building, so we don't need to rely on copying the source
366
+ # from the image.
367
+ # TODO(metzman): Figure out if we want second copy at all.
368
+ manager = self._clone_repo_and_checkout(self.config.git_url,
369
+ self.config.project_repo_name)
370
+ return self._build_external_project_docker_image(manager)
371
+
372
+ def get_build_command(self, host_repo_path, image_repo_path): # pylint: disable=no-self-use
373
+ """Returns the command for building the project that is run inside the
374
+ project builder container."""
375
+ return get_build_command()
local-test-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/http_utils_test.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Tests for http_utils.py"""
15
+
16
+ import unittest
17
+ from unittest import mock
18
+
19
+ from pyfakefs import fake_filesystem_unittest
20
+
21
+ import http_utils
22
+
23
+ mock_get_response = mock.MagicMock(status_code=200, content=b'')
24
+
25
+
26
+ class DownloadUrlTest(unittest.TestCase):
27
+ """Tests that download_url works."""
28
+ URL = 'https://example.com/file'
29
+ FILE_PATH = '/tmp/file'
30
+
31
+ @mock.patch('time.sleep')
32
+ @mock.patch('requests.get', return_value=mock_get_response)
33
+ def test_download_url_no_error(self, mock_urlretrieve, _):
34
+ """Tests that download_url works when there is no error."""
35
+ self.assertTrue(http_utils.download_url(self.URL, self.FILE_PATH))
36
+ self.assertEqual(1, mock_urlretrieve.call_count)
37
+
38
+ @mock.patch('time.sleep')
39
+ @mock.patch('logging.error')
40
+ @mock.patch('requests.get',
41
+ return_value=mock.MagicMock(status_code=404, content=b''))
42
+ def test_download_url_http_error(self, mock_get, mock_error, _):
43
+ """Tests that download_url doesn't retry when there is an HTTP error."""
44
+ self.assertFalse(http_utils.download_url(self.URL, self.FILE_PATH))
45
+ mock_error.assert_called_with(
46
+ 'Unable to download from: %s. Code: %d. Content: %s.', self.URL, 404,
47
+ b'')
48
+ self.assertEqual(1, mock_get.call_count)
49
+
50
+ @mock.patch('time.sleep')
51
+ @mock.patch('requests.get', side_effect=ConnectionResetError)
52
+ def test_download_url_connection_error(self, mock_get, mock_sleep):
53
+ """Tests that download_url doesn't retry when there is an HTTP error."""
54
+ self.assertFalse(http_utils.download_url(self.URL, self.FILE_PATH))
55
+ self.assertEqual(4, mock_get.call_count)
56
+ self.assertEqual(3, mock_sleep.call_count)
57
+
58
+
59
+ class DownloadAndUnpackZipTest(fake_filesystem_unittest.TestCase):
60
+ """Tests download_and_unpack_zip."""
61
+
62
+ def setUp(self):
63
+ self.setUpPyfakefs()
64
+
65
+ @mock.patch('requests.get', return_value=mock_get_response)
66
+ def test_bad_zip_download(self, _):
67
+ """Tests download_and_unpack_zip returns none when a bad zip is passed."""
68
+ self.fs.create_file('/url_tmp.zip', contents='Test file.')
69
+ self.assertFalse(
70
+ http_utils.download_and_unpack_zip('/not/a/real/url',
71
+ '/extract-directory'))
local-test-commons-compress-delta-02/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-commons-compress-delta-02/fuzz-tooling/infra/cifuzz/run_cifuzz.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Script for running CIFuzz end-to-end. This is meant to work outside any
15
+ docker image. This cannot depend on any CIFuzz code or third party packages."""
16
+ import os
17
+ import subprocess
18
+ import sys
19
+ import tempfile
20
+ import logging
21
+
22
+ INFRA_DIR = os.path.dirname(os.path.dirname(__file__))
23
+ DEFAULT_ENVS = [('DRY_RUN', '0'), ('SANITIZER', 'address')]
24
+ BASE_CIFUZZ_DOCKER_TAG = 'ghcr.io/aixcc-finals'
25
+
26
+
27
+ def set_default_env_var_if_unset(env_var, default_value):
28
+ """Sets the value of |env_var| in the environment to |default_value| if it was
29
+ not already set."""
30
+ if env_var not in os.environ:
31
+ os.environ[env_var] = default_value
32
+
33
+
34
+ def docker_run(name, workspace, project_src_path):
35
+ """Runs a CIFuzz docker container with |name|."""
36
+ command = [
37
+ 'docker', 'run', '--name', name, '--rm', '-e', 'PROJECT_SRC_PATH', '-e',
38
+ 'OSS_FUZZ_PROJECT_NAME', '-e', 'WORKSPACE', '-e', 'REPOSITORY', '-e',
39
+ 'DRY_RUN', '-e', 'CI', '-e', 'SANITIZER', '-e', 'GIT_SHA', '-e',
40
+ 'FILESTORE', '-e', 'NO_CLUSTERFUZZ_DEPLOYMENT'
41
+ ]
42
+ if project_src_path:
43
+ command += ['-v', f'{project_src_path}:{project_src_path}']
44
+ command += [
45
+ '-v', '/var/run/docker.sock:/var/run/docker.sock', '-v',
46
+ f'{workspace}:{workspace}', f'{BASE_CIFUZZ_DOCKER_TAG}/{name}'
47
+ ]
48
+ print('Running docker command:', command)
49
+ subprocess.run(command, check=True)
50
+
51
+
52
+ def docker_build(image):
53
+ """Builds the CIFuzz |image|. Only suitable for building CIFuzz images."""
54
+ command = [
55
+ 'docker', 'build', '-t', f'{BASE_CIFUZZ_DOCKER_TAG}/{image}', '--file',
56
+ f'{image}.Dockerfile', '.'
57
+ ]
58
+ subprocess.run(command, check=True, cwd=INFRA_DIR)
59
+
60
+
61
+ def main():
62
+ """Builds and runs fuzzers using CIFuzz."""
63
+ for env_var, default_value in DEFAULT_ENVS:
64
+ set_default_env_var_if_unset(env_var, default_value)
65
+
66
+ repository = os.getenv('REPOSITORY')
67
+ assert repository
68
+
69
+ project_src_path = os.getenv('PROJECT_SRC_PATH')
70
+
71
+ with tempfile.TemporaryDirectory() as temp_dir:
72
+ if 'WORKSPACE' not in os.environ:
73
+ os.environ['WORKSPACE'] = temp_dir
74
+
75
+ workspace = os.environ['WORKSPACE']
76
+
77
+ docker_build('build_fuzzers')
78
+ docker_run('build_fuzzers', workspace, project_src_path)
79
+ docker_build('run_fuzzers')
80
+ try:
81
+ docker_run('run_fuzzers', workspace, project_src_path)
82
+ except subprocess.CalledProcessError:
83
+ logging.error('run_fuzzers failed.')
84
+ return 1
85
+ return 0
86
+
87
+
88
+ if __name__ == '__main__':
89
+ sys.exit(main())
local-test-commons-compress-delta-02/fuzz-tooling/infra/tools/hold_back_images.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+ """Script for pinning builder images for projects that break on upgrades. Works
18
+ with projects that use language builders."""
19
+ import argparse
20
+ import logging
21
+ import os
22
+ import re
23
+ import sys
24
+ import subprocess
25
+
26
+ ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
27
+ PROJECTS_DIR = os.path.join(ROOT_DIR, 'projects')
28
+
29
+ IMAGE_DIGEST_REGEX = re.compile(r'\[(.+)\]\n')
30
+ FROM_LINE_REGEX = re.compile(
31
+ r'FROM (ghcr.io\/aixcc-finals\/base-builder[\-a-z0-9]*)(\@?.*)')
32
+
33
+
34
+ def get_latest_docker_image_digest(image):
35
+ """Returns a pinnable version of the latest |image|. This version will have a
36
+ SHA."""
37
+ subprocess.run(['docker', 'pull', image], check=True)
38
+ subprocess.run(['docker', 'pull', image], stdout=subprocess.PIPE, check=True)
39
+
40
+ command = [
41
+ 'docker', 'image', 'inspect', '--format', '{{.RepoDigests}}', image
42
+ ]
43
+ output = subprocess.run(command, check=True,
44
+ stdout=subprocess.PIPE).stdout.decode('utf-8')
45
+ return IMAGE_DIGEST_REGEX.match(output).groups(1)[0]
46
+
47
+
48
+ def get_args():
49
+ """Returns parsed arguments."""
50
+ parser = argparse.ArgumentParser(sys.argv[0],
51
+ description='Hold back builder images.')
52
+ parser.add_argument('projects', help='Projects.', nargs='+')
53
+
54
+ parser.add_argument('--hold-image-digest',
55
+ required=False,
56
+ nargs='?',
57
+ default=None,
58
+ help='Image to hold on to.')
59
+
60
+ parser.add_argument('--update-held',
61
+ action='store_true',
62
+ default=False,
63
+ help='Update held images.')
64
+
65
+ parser.add_argument('--issue-number',
66
+ required=False,
67
+ nargs='?',
68
+ default=None,
69
+ help='Issue to reference.')
70
+
71
+ args = parser.parse_args()
72
+ return args
73
+
74
+
75
+ def get_hold_image_digest(line, hold_image_digest, update_held):
76
+ """Returns the image digest for the |line| we want to pin. If the image is
77
+ already pinned then it is only updated if |update_held. If |hold_image_digest
78
+ is specified then it is returned, otherwise the latest pinnable version is
79
+ returned."""
80
+ matches = FROM_LINE_REGEX.match(line).groups()
81
+ if matches[1] and not update_held:
82
+ return None, False
83
+ initial_image = matches[0]
84
+ if hold_image_digest:
85
+ return hold_image_digest, True
86
+ return get_latest_docker_image_digest(initial_image), True
87
+
88
+
89
+ def hold_image(project, hold_image_digest, update_held, issue_number):
90
+ """Rewrites the Dockerfile of |project| to pin the base-builder image on
91
+ upgrade."""
92
+ dockerfile_path = os.path.join(PROJECTS_DIR, project, 'Dockerfile')
93
+ with open(dockerfile_path, 'r') as dockerfile_handle:
94
+ dockerfile = dockerfile_handle.readlines()
95
+ for idx, line in enumerate(dockerfile[:]):
96
+ if not line.startswith('FROM ghcr.io/aixcc-finals/base-builder'):
97
+ continue
98
+
99
+ hold_image_digest, should_hold = get_hold_image_digest(
100
+ line.strip(), hold_image_digest, update_held)
101
+ if not should_hold:
102
+ logging.error('Not holding back %s.', project)
103
+ break
104
+ dockerfile[idx] = f'FROM {hold_image_digest}\n'
105
+ if issue_number:
106
+ comment = ('# Held back because of github.com/google/oss-fuzz/pull/'
107
+ f'{issue_number}\n# Please fix failure and upgrade.\n')
108
+ dockerfile.insert(idx, comment)
109
+ break
110
+ else:
111
+ # This path is taken when we don't break out of the loop.
112
+ assert None, f'Could not find FROM line in {project}'
113
+ dockerfile = ''.join(dockerfile)
114
+ with open(dockerfile_path, 'w') as dockerfile_handle:
115
+ dockerfile_handle.write(dockerfile)
116
+
117
+
118
+ def main():
119
+ """Script for pinning builder images for projects that break on upgrades."""
120
+ args = get_args()
121
+ for project in args.projects:
122
+ hold_image(project, args.hold_image_digest, args.update_held,
123
+ args.issue_number)
124
+ return 0
125
+
126
+
127
+ if __name__ == '__main__':
128
+ sys.exit(main())
local-test-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 {commandHistory} from '../commandUtils';
20
+ import {
21
+ hasOssFuzzInWorkspace,
22
+ getOssFuzzWorkspaceProjectName,
23
+ setStatusText,
24
+ } from '../utils';
25
+ import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
26
+
27
+ export async function cmdInputCollectorBuildFuzzersFromWorkspace() {
28
+ let ossFuzzProjectName = '';
29
+ // First determine if we have a name in the workspace
30
+ if (await hasOssFuzzInWorkspace()) {
31
+ /**
32
+ * The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
33
+ */
34
+ ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
35
+ } else {
36
+ // If we did not have that, ask the user.
37
+
38
+ const ossFuzzProjectNameInput = await vscode.window.showInputBox({
39
+ value: '',
40
+ placeHolder: 'The OSS-Fuzz project name',
41
+ });
42
+ if (!ossFuzzProjectNameInput) {
43
+ println('Did not get a ossFuzzTargetProject');
44
+ return false;
45
+ }
46
+ ossFuzzProjectName = ossFuzzProjectNameInput.toString();
47
+ }
48
+
49
+ // Create an history object
50
+ const args = new Object({
51
+ projectName: ossFuzzProjectName,
52
+ sanitizer: '',
53
+ toClean: false,
54
+ });
55
+
56
+ const commandObject = new Object({
57
+ commandType: 'oss-fuzz.WSBuildFuzzers',
58
+ Arguments: args,
59
+ dispatcherFunc: cmdDispatchBuildFuzzersFromWorkspace,
60
+ });
61
+ console.log('L1: ' + commandHistory.length);
62
+ commandHistory.push(commandObject);
63
+
64
+ await cmdDispatchBuildFuzzersFromWorkspace(args);
65
+ return true;
66
+ }
67
+
68
+ async function cmdDispatchBuildFuzzersFromWorkspace(args: any) {
69
+ await setStatusText('Building fuzzers: starting');
70
+ const res = await buildFuzzersFromWorkspace(
71
+ args.projectName,
72
+ args.sanitizer,
73
+ args.toClean
74
+ );
75
+ if (res) {
76
+ await setStatusText('Building fuzzers: finished');
77
+ } else {
78
+ await setStatusText('Building fuzzers: failed');
79
+ }
80
+ }
local-test-commons-compress-delta-02/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-commons-compress-delta-02/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-commons-compress-delta-02/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.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 {runFuzzIntrospector} from '../fuzzIntrospectorHelper';
18
+
19
+ /**
20
+ * Function for setting up Fuzz Introspector by way of a Python virtual env.
21
+ */
22
+ export async function runFuzzIntrospectorHandler() {
23
+ runFuzzIntrospector();
24
+ }
local-test-commons-compress-delta-02/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-commons-compress-delta-02/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
+ }