Skip to content

Commit 4785d35

Browse files
Optimize WEB_TESTS_URL download and extraction
- Add `web_tests_url` to `FuzzTaskInput` proto and recompile. - Sign `WEB_TESTS_URL` in `fuzz_task` preprocess. - In `utask_main`, if blackbox fuzzing, pass signed URL to `update_tests_if_needed`. - In `update_tests_if_needed`, handle signed URL (downloading to file if http). - Use `unzip -q` for extraction if available for speed, falling back to `archive` module. - Refactor defensive checks in `fuzz_task`.
1 parent 64260c1 commit 4785d35

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import datetime
1717
import os
1818
import platform
19+
import shutil
1920
import sys
2021
import time
2122

@@ -324,20 +325,18 @@ def update_tests_if_needed(tests_url=None):
324325
for _ in range(retry_limit):
325326
try:
326327
shell.remove_directory(data_directory, recreate=True)
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)
328+
if tests_url.startswith('http'):
329+
storage.download_signed_url_to_file(tests_url, temp_archive)
331330
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)
331+
storage.copy_file_from(tests_url, temp_archive)
336332

333+
if shutil.which('unzip'):
334+
shell.execute_command(
335+
'unzip -q -o %s -d %s' % (temp_archive, data_directory))
336+
else:
337337
with archive.open(temp_archive) as reader:
338338
reader.extract_all(data_directory, trusted=True)
339-
shell.remove_file(temp_archive)
340-
339+
shell.remove_file(temp_archive)
341340
error_occured = False
342341
break
343342
except:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ def _get_fuzz_target(uworker_input):
20982098

20992099
def utask_main(uworker_input):
21002100
"""Runs the given fuzzer for one round."""
2101-
if uworker_input.fuzz_task_input.HasField('web_tests_url'):
2101+
if not engine.get(uworker_input.fuzzer_name):
21022102
update_task.update_tests_if_needed(
21032103
uworker_input.fuzz_task_input.web_tests_url)
21042104

0 commit comments

Comments
 (0)