Skip to content

Commit

Permalink
Fix docker image tag by removing trailing special chars in benchmark …
Browse files Browse the repository at this point in the history
…id (#125)

Continue from #111 to fix #115.

Some `benchmark.id` has a trailing `_`, which caused [this
error](#115 (comment))
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}`.
  • Loading branch information
DonggeLiu authored Feb 27, 2024
1 parent 79c6f1a commit 2e3e92a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions experiment/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2e3e92a

Please sign in to comment.