Skip to content

Commit 64260c1

Browse files
Sign WEB_TESTS_URL in fuzzing preprocess and use HttpZipFile for faster download
- Add `web_tests_url` field to `FuzzTaskInput` proto. - Sign `WEB_TESTS_URL` in `fuzz_task.py` preprocess and pass it to `utask_main`. - In `utask_main`, call `update_tests_if_needed` with the signed URL. - Update `update_tests_if_needed` in `update_task.py` to accept `tests_url`. - Use `archive.HttpZipFile` for streaming extraction of the signed URL if compatible, avoiding large file download to disk. - Recompile `uworker_msg.proto`.
1 parent 28e1d2a commit 64260c1

File tree

4 files changed

+98
-90
lines changed

4 files changed

+98
-90
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,15 @@ def update_source_code():
288288
f'(release = {utils.get_clusterfuzz_release()}).')
289289

290290

291-
def update_tests_if_needed():
291+
def update_tests_if_needed(tests_url=None):
292292
"""Updates layout tests every day."""
293293
data_directory = environment.get_value('FUZZ_DATA')
294294
error_occured = False
295295
expected_task_duration = 60 * 60 # 1 hour.
296296
retry_limit = environment.get_value('FAIL_RETRIES')
297297
temp_archive = os.path.join(data_directory, 'temp.zip')
298-
tests_url = environment.get_value('WEB_TESTS_URL')
298+
if not tests_url:
299+
tests_url = environment.get_value('WEB_TESTS_URL')
299300

300301
# Check if we have a valid tests url.
301302
if not tests_url:
@@ -323,10 +324,20 @@ def update_tests_if_needed():
323324
for _ in range(retry_limit):
324325
try:
325326
shell.remove_directory(data_directory, recreate=True)
326-
storage.copy_file_from(tests_url, temp_archive)
327-
with archive.open(temp_archive) as reader:
328-
reader.extract_all(data_directory, trusted=True)
329-
shell.remove_file(temp_archive)
327+
if tests_url.startswith('http') and archive.HttpZipFile.is_uri_compatible(
328+
tests_url):
329+
with archive.ZipArchiveReader(archive.HttpZipFile(tests_url)) as reader:
330+
reader.extract_all(data_directory, trusted=True)
331+
else:
332+
if tests_url.startswith('http'):
333+
storage.download_signed_url_to_file(tests_url, temp_archive)
334+
else:
335+
storage.copy_file_from(tests_url, temp_archive)
336+
337+
with archive.open(temp_archive) as reader:
338+
reader.extract_all(data_directory, trusted=True)
339+
shell.remove_file(temp_archive)
340+
330341
error_occured = False
331342
break
332343
except:

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from clusterfuzz._internal.bot.tasks import setup
3939
from clusterfuzz._internal.bot.tasks import task_creation
4040
from clusterfuzz._internal.bot.tasks import trials
41+
from clusterfuzz._internal.bot.tasks import update_task
4142
from clusterfuzz._internal.bot.tasks.utasks import fuzz_task_knobs
4243
from clusterfuzz._internal.bot.tasks.utasks import uworker_handle_errors
4344
from clusterfuzz._internal.bot.tasks.utasks import uworker_io
@@ -2097,6 +2098,10 @@ def _get_fuzz_target(uworker_input):
20972098

20982099
def utask_main(uworker_input):
20992100
"""Runs the given fuzzer for one round."""
2101+
if uworker_input.fuzz_task_input.HasField('web_tests_url'):
2102+
update_task.update_tests_if_needed(
2103+
uworker_input.fuzz_task_input.web_tests_url)
2104+
21002105
# Sets fuzzing logs context before running the fuzzer.
21012106
fuzz_target = _get_fuzz_target(uworker_input)
21022107
with logs.fuzzer_log_context(uworker_input.fuzzer_name,
@@ -2191,6 +2196,11 @@ def _utask_preprocess(fuzzer_name, job_type, uworker_env):
21912196
use_backup=True).serialize())
21922197

21932198
fuzz_task_input.trials.extend(trials.preprocess_get_db_trials())
2199+
web_tests_url = environment.get_value('WEB_TESTS_URL')
2200+
if web_tests_url:
2201+
fuzz_task_input.web_tests_url = storage.get_signed_download_url(
2202+
web_tests_url)
2203+
21942204
for _ in range(MAX_CRASHES_UPLOADED):
21952205
url = fuzz_task_input.crash_upload_urls.add()
21962206
url.key = blobs.generate_new_blob_name()

src/clusterfuzz/_internal/protos/uworker_msg.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ message FuzzTaskInput {
5353
repeated string global_blacklisted_functions = 6;
5454
repeated BlobUploadUrl crash_upload_urls = 7;
5555
repeated google.protobuf.Any trials = 8;
56+
optional string web_tests_url = 9;
5657
}
5758

5859
message DataBundleCorpus {

0 commit comments

Comments
 (0)