Skip to content

Commit 970c2ce

Browse files
[rearch][fuzz_task] Get data bundle directory in safe way. (#4202)
Related #3008
1 parent fd7df03 commit 970c2ce

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

src/clusterfuzz/_internal/bot/tasks/setup.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ def _prepare_update_data_bundle(fuzzer, data_bundle):
467467
return data_bundle_directory
468468

469469

470-
def update_data_bundle(
470+
def _update_data_bundle(
471471
fuzzer: data_types.Fuzzer,
472-
data_bundle_corpus: uworker_msg_pb2.DataBundleCorpus) -> bool: # pylint: disable=no-member
472+
data_bundle_corpus: uworker_msg_pb2.DataBundleCorpus) -> Optional[str]: # pylint: disable=no-member
473473
"""Updates a data bundle to the latest version."""
474474
data_bundle = uworker_io.entity_from_protobuf(data_bundle_corpus.data_bundle,
475475
data_types.DataBundle)
@@ -656,7 +656,7 @@ def _set_up_data_bundles(update_input: uworker_msg_pb2.SetupInput): # pylint: d
656656
fuzzer = uworker_io.entity_from_protobuf(update_input.fuzzer,
657657
data_types.Fuzzer)
658658
for data_bundle_corpus in update_input.data_bundle_corpuses:
659-
if not update_data_bundle(fuzzer, data_bundle_corpus):
659+
if not _update_data_bundle(fuzzer, data_bundle_corpus):
660660
return False
661661

662662
return True
@@ -744,16 +744,6 @@ def _is_data_bundle_up_to_date(data_bundle, data_bundle_directory):
744744
return False
745745

746746

747-
def trusted_get_data_bundle_directory(fuzzer):
748-
"""For fuzz_task which doesn't get data bundles in an untrusted manner."""
749-
# TODO(metzman): Delete this when fuzz_task is migrated.
750-
# Check if we have a fuzzer-specific data bundle. Use it to calculate the
751-
# data directory we will fetch our testcases from.
752-
data_bundle = data_types.DataBundle.query(
753-
data_types.DataBundle.name == fuzzer.data_bundle_name).get()
754-
return get_data_bundle_directory(fuzzer, data_bundle)
755-
756-
757747
def get_data_bundle_directory(fuzzer, data_bundle):
758748
"""Return data bundle data directory."""
759749
# Store corpora for built-in fuzzers like libFuzzer in the same directory

src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,9 @@ def run(self):
17831783

17841784
# Data bundle directories can also have testcases which are kept in-place
17851785
# because of dependencies.
1786-
self.data_directory = setup.trusted_get_data_bundle_directory(self.fuzzer)
1786+
self.data_directory = setup.get_data_bundle_directory(
1787+
self.fuzzer, self.uworker_input.setup_input.data_bundle_corpuses)
1788+
17871789
if not self.data_directory:
17881790
logs.error(
17891791
'Unable to setup data bundle %s.' % self.fuzzer.data_bundle_name)

src/clusterfuzz/_internal/tests/core/bot/tasks/setup_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def setUp(self):
214214
'clusterfuzz._internal.bot.tasks.task_types.is_remote_utask',
215215
'clusterfuzz._internal.bot.tasks.setup._update_fuzzer',
216216
'clusterfuzz._internal.bot.tasks.setup._clear_old_data_bundles_if_needed',
217-
'clusterfuzz._internal.bot.tasks.setup.update_data_bundle',
217+
'clusterfuzz._internal.bot.tasks.setup._update_data_bundle',
218218
])
219219
self.mock.get_signed_upload_url.return_value = 'https://fake/upload'
220220
self.mock.get_signed_download_url.return_value = 'https://fake/download'
@@ -234,4 +234,4 @@ def test_data_bundles(self):
234234
setup_input = setup.preprocess_update_fuzzer_and_data_bundles(
235235
self.fuzzer_name)
236236
setup.update_fuzzer_and_data_bundles(setup_input)
237-
self.assertEqual(self.mock.update_data_bundle.call_count, 2)
237+
self.assertEqual(self.mock._update_data_bundle.call_count, 2)

src/clusterfuzz/_internal/tests/core/bot/untrusted_runner/untrusted_runner_integration_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
from clusterfuzz._internal.system import shell
4242
from clusterfuzz._internal.tests.test_libs import untrusted_runner_helpers
4343

44+
# pylint: disable=protected-access
45+
4446
TEST_FILE_CONTENTS = (b'A' * config.FILE_TRANSFER_CHUNK_SIZE +
4547
b'B' * config.FILE_TRANSFER_CHUNK_SIZE +
4648
b'C' * (config.FILE_TRANSFER_CHUNK_SIZE // 2))
@@ -513,7 +515,7 @@ def test_symbolize(self):
513515
self.assertEqual(expected_symbolized_stacktrace, symbolized_stacktrace)
514516

515517
def test_update_data_bundle(self):
516-
"""Test update_data_bundle."""
518+
"""Test _update_data_bundle."""
517519
self.mock.get_data_bundle_bucket_name.return_value = TEST_BUNDLE_BUCKET
518520

519521
# Get a blobstore key for the fuzzer.
@@ -536,15 +538,15 @@ def test_update_data_bundle(self):
536538
data_bundle_corpus.data_bundle.CopyFrom(
537539
uworker_io.entity_to_protobuf(bundle))
538540
self.assertTrue(
539-
setup.update_data_bundle(returned_fuzzer, data_bundle_corpus))
541+
setup._update_data_bundle(returned_fuzzer, data_bundle_corpus))
540542

541543
data_bundle_directory = file_host.rebase_to_worker_root(
542544
setup.get_data_bundle_directory(returned_fuzzer, bundle))
543545
self.assertTrue(os.path.exists(os.path.join(data_bundle_directory, 'a')))
544546
self.assertTrue(os.path.exists(os.path.join(data_bundle_directory, 'b')))
545547

546548
self.assertTrue(
547-
setup.update_data_bundle(returned_fuzzer, data_bundle_corpus))
549+
setup._update_data_bundle(returned_fuzzer, data_bundle_corpus))
548550

549551
def test_get_fuzz_targets(self):
550552
"""Test get_fuzz_targets."""

0 commit comments

Comments
 (0)