From 2e3e92a9e2d1b7be752afd02e3e392dc03f5d6d9 Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Tue, 27 Feb 2024 15:59:09 +1100 Subject: [PATCH] Fix docker image tag by removing trailing special chars in benchmark id (#125) Continue from #111 to fix #115. Some `benchmark.id` has a trailing `_`, which caused [this error](https://github.com/google/oss-fuzz-gen/issues/115#issuecomment-1953133383) when concat with `-{sample_id}`. This PR fixes this error and cleans up code by moving all steps to fix the docker tag after appending `-{sample_id}`. --- experiment/evaluator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/experiment/evaluator.py b/experiment/evaluator.py index 1002f08aaa..847a4cd65e 100644 --- a/experiment/evaluator.py +++ b/experiment/evaluator.py @@ -107,6 +107,15 @@ def load_existing_coverage_summary(project: str) -> dict: return json.load(f) +def _rectify_docker_tag(docker_tag: str) -> str: + # Replace "::" and any character not \w, _, or . with "-". + valid_docker_tag = re.sub(r'::', '-', docker_tag) + valid_docker_tag = re.sub(r'[^\w_.]', '-', valid_docker_tag) + # Docker fails with tags containing -_ or _-. + valid_docker_tag = re.sub(r'[-_]{2,}', '-', valid_docker_tag) + return valid_docker_tag + + # TODO(Dongge): Make this universally available. class _Logger: """Log evaluation progress.""" @@ -202,12 +211,8 @@ def do_check_target(self, ai_binary: str, target_path: str) -> Result: """Builds and runs a target.""" generated_target_name = os.path.basename(target_path) sample_id = os.path.splitext(generated_target_name)[0] - # Replace "::" and any character not \w, _, or . with "-". - valid_docker_tag_name = re.sub(r'::', '-', self.benchmark.id) - valid_docker_tag_name = re.sub(r'[^\w_.]', '-', valid_docker_tag_name) - # Docker fails with tags containing -_ or _-. - valid_docker_tag_name = re.sub(r'[-_]{2,}', '-', valid_docker_tag_name) - generated_oss_fuzz_project = f'{valid_docker_tag_name}-{sample_id}' + generated_oss_fuzz_project = f'{self.benchmark.id}-{sample_id}' + generated_oss_fuzz_project = _rectify_docker_tag(generated_oss_fuzz_project) self.create_ossfuzz_project(generated_oss_fuzz_project, target_path) status_path = os.path.join(self.work_dirs.status, sample_id)