prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Should local docker run restrict cpu to 1 to match FuzzBench prod environment ?
  See also
  https://github.com/google/fuzzbench/issues/173#issuecomment-605283610
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `common/fuzzer_utils.py`
  Content:
  ```
  1 # Copyright 2020 Google LLC
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #      http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 """Fuzzer helpers."""
  15 
  16 import importlib
  17 import os
  18 import re
  19 from typing import Optional
  20 
  21 from common import logs
  22 from common import utils
  23 from common import yaml_utils
  24 
  25 DEFAULT_FUZZ_TARGET_NAME = 'fuzz-target'
  26 FUZZ_TARGET_SEARCH_STRING = b'LLVMFuzzerTestOneInput'
  27 VALID_FUZZER_REGEX = re.compile(r'^[A-Za-z0-9_]+$')
  28 
  29 
  30 def get_fuzz_target_binary(search_directory: str,
  31                            fuzz_target_name: str) -> Optional[str]:
  32     """Return target binary path."""
  33     if fuzz_target_name:
  34         fuzz_target_binary = os.path.join(search_directory, fuzz_target_name)
  35         if os.path.exists(fuzz_target_binary):
  36             return fuzz_target_binary
  37         return None
  38 
  39     default_fuzz_target_binary = os.path.join(search_directory,
  40                                               DEFAULT_FUZZ_TARGET_NAME)
  41     if os.path.exists(default_fuzz_target_binary):
  42         return default_fuzz_target_binary
  43 
  44     for root, _, files in os.walk(search_directory):
  45         if root == 'uninstrumented':
  46             continue
  47         for filename in files:
  48             if filename.endswith('-uninstrumented'):
  49                 # Skip uninstrumented binaries (e.g. with QSYM).
  50                 continue
  51 
  52             file_path = os.path.join(root, filename)
  53             with open(file_path, 'rb') as file_handle:
  54                 if FUZZ_TARGET_SEARCH_STRING in file_handle.read():
  55                     return file_path
  56 
  57     return None
  58 
  59 
  60 def validate(fuzzer):
  61     """Return True if |fuzzer| is a valid fuzzbench fuzzer."""
  62     # Although importing probably allows a subset of what the regex allows, use
  63     # the regex anyway to be safe. The regex is enforcing that the fuzzer is a
  64     # valid path for GCS or a linux system.
  65     if VALID_FUZZER_REGEX.match(fuzzer) is None:
  66         logs.error('%s does not conform to %s pattern.', fuzzer,
  67                    VALID_FUZZER_REGEX.pattern)
  68         return False
  69 
  70     # Try importing the fuzzer module.
  71     module_name = 'fuzzers.{}.fuzzer'.format(fuzzer)
  72     try:
  73         importlib.import_module(module_name)
  74         return True
  75     except Exception as error:  # pylint: disable=broad-except
  76         logs.error('Encountered "%s" while trying to import %s.', error,
  77                    module_name)
  78         return False
  79 
  80 
  81 def get_fuzzer_configs(fuzzers=None):
  82     """Returns the list of all fuzzers."""
  83     fuzzers_dir = os.path.join(utils.ROOT_DIR, 'fuzzers')
  84     fuzzer_configs = []
  85     for fuzzer in os.listdir(fuzzers_dir):
  86         if not os.path.isfile(os.path.join(fuzzers_dir, fuzzer, 'fuzzer.py')):
  87             continue
  88         if fuzzer == 'coverage':
  89             continue
  90 
  91         if not fuzzers or fuzzer in fuzzers:
  92             # Auto-generate the default configuration for each base fuzzer.
  93             fuzzer_configs.append({'fuzzer': fuzzer})
  94 
  95         variant_config_path = os.path.join(fuzzers_dir, fuzzer, 'variants.yaml')
  96         if not os.path.isfile(variant_config_path):
  97             continue
  98 
  99         variant_config = yaml_utils.read(variant_config_path)
  100         assert 'variants' in variant_config, (
  101             'Missing "variants" section of {}'.format(variant_config_path))
  102         for variant in variant_config['variants']:
  103             if not fuzzers or variant['name'] in fuzzers:
  104                 # Modify the config from the variants.yaml format to the
  105                 # format expected by a fuzzer config.
  106                 assert 'name' in variant, (
  107                     'Missing name attribute for fuzzer variant in {}'.format(
  108                         variant_config_path))
  109                 variant['variant_name'] = variant['name']
  110                 del variant['name']
  111                 variant['fuzzer'] = fuzzer
  112                 fuzzer_configs.append(variant)
  113 
  114     return fuzzer_configs
  115
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/common/fuzzer_utils.py b/common/fuzzer_utils.py
  --- a/common/fuzzer_utils.py
  +++ b/common/fuzzer_utils.py
  @@ -20,7 +20,6 @@
   
   from common import logs
   from common import utils
  -from common import yaml_utils
   
   DEFAULT_FUZZ_TARGET_NAME = 'fuzz-target'
   FUZZ_TARGET_SEARCH_STRING = b'LLVMFuzzerTestOneInput'
  @@ -80,6 +79,10 @@
   
   def get_fuzzer_configs(fuzzers=None):
       """Returns the list of all fuzzers."""
  +    # Import it here to avoid yaml dependency in runner.
  +    # pylint: disable=import-outside-toplevel
  +    from common import yaml_utils
  +
       fuzzers_dir = os.path.join(utils.ROOT_DIR, 'fuzzers')
       fuzzer_configs = []
       for fuzzer in os.listdir(fuzzers_dir):
  
verification_info: {"golden_diff": "diff --git a/common/fuzzer_utils.py b/common/fuzzer_utils.py\n--- a/common/fuzzer_utils.py\n+++ b/common/fuzzer_utils.py\n@@ -20,7 +20,6 @@\n \n from common import logs\n from common import utils\n-from common import yaml_utils\n \n DEFAULT_FUZZ_TARGET_NAME = 'fuzz-target'\n FUZZ_TARGET_SEARCH_STRING = b'LLVMFuzzerTestOneInput'\n@@ -80,6 +79,10 @@\n \n def get_fuzzer_configs(fuzzers=None):\n     \"\"\"Returns the list of all fuzzers.\"\"\"\n+    # Import it here to avoid yaml dependency in runner.\n+    # pylint: disable=import-outside-toplevel\n+    from common import yaml_utils\n+\n     fuzzers_dir = os.path.join(utils.ROOT_DIR, 'fuzzers')\n     fuzzer_configs = []\n     for fuzzer in os.listdir(fuzzers_dir):\n", "issue": "Should local docker run restrict cpu to 1 to match FuzzBench prod environment ?\nSee also\r\nhttps://github.com/google/fuzzbench/issues/173#issuecomment-605283610\n", "before_files": [{"content": "# Copyright 2020 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Fuzzer helpers.\"\"\"\n\nimport importlib\nimport os\nimport re\nfrom typing import Optional\n\nfrom common import logs\nfrom common import utils\nfrom common import yaml_utils\n\nDEFAULT_FUZZ_TARGET_NAME = 'fuzz-target'\nFUZZ_TARGET_SEARCH_STRING = b'LLVMFuzzerTestOneInput'\nVALID_FUZZER_REGEX = re.compile(r'^[A-Za-z0-9_]+$')\n\n\ndef get_fuzz_target_binary(search_directory: str,\n                           fuzz_target_name: str) -> Optional[str]:\n    \"\"\"Return target binary path.\"\"\"\n    if fuzz_target_name:\n        fuzz_target_binary = os.path.join(search_directory, fuzz_target_name)\n        if os.path.exists(fuzz_target_binary):\n            return fuzz_target_binary\n        return None\n\n    default_fuzz_target_binary = os.path.join(search_directory,\n                                              DEFAULT_FUZZ_TARGET_NAME)\n    if os.path.exists(default_fuzz_target_binary):\n        return default_fuzz_target_binary\n\n    for root, _, files in os.walk(search_directory):\n        if root == 'uninstrumented':\n            continue\n        for filename in files:\n            if filename.endswith('-uninstrumented'):\n                # Skip uninstrumented binaries (e.g. with QSYM).\n                continue\n\n            file_path = os.path.join(root, filename)\n            with open(file_path, 'rb') as file_handle:\n                if FUZZ_TARGET_SEARCH_STRING in file_handle.read():\n                    return file_path\n\n    return None\n\n\ndef validate(fuzzer):\n    \"\"\"Return True if |fuzzer| is a valid fuzzbench fuzzer.\"\"\"\n    # Although importing probably allows a subset of what the regex allows, use\n    # the regex anyway to be safe. The regex is enforcing that the fuzzer is a\n    # valid path for GCS or a linux system.\n    if VALID_FUZZER_REGEX.match(fuzzer) is None:\n        logs.error('%s does not conform to %s pattern.', fuzzer,\n                   VALID_FUZZER_REGEX.pattern)\n        return False\n\n    # Try importing the fuzzer module.\n    module_name = 'fuzzers.{}.fuzzer'.format(fuzzer)\n    try:\n        importlib.import_module(module_name)\n        return True\n    except Exception as error:  # pylint: disable=broad-except\n        logs.error('Encountered \"%s\" while trying to import %s.', error,\n                   module_name)\n        return False\n\n\ndef get_fuzzer_configs(fuzzers=None):\n    \"\"\"Returns the list of all fuzzers.\"\"\"\n    fuzzers_dir = os.path.join(utils.ROOT_DIR, 'fuzzers')\n    fuzzer_configs = []\n    for fuzzer in os.listdir(fuzzers_dir):\n        if not os.path.isfile(os.path.join(fuzzers_dir, fuzzer, 'fuzzer.py')):\n            continue\n        if fuzzer == 'coverage':\n            continue\n\n        if not fuzzers or fuzzer in fuzzers:\n            # Auto-generate the default configuration for each base fuzzer.\n            fuzzer_configs.append({'fuzzer': fuzzer})\n\n        variant_config_path = os.path.join(fuzzers_dir, fuzzer, 'variants.yaml')\n        if not os.path.isfile(variant_config_path):\n            continue\n\n        variant_config = yaml_utils.read(variant_config_path)\n        assert 'variants' in variant_config, (\n            'Missing \"variants\" section of {}'.format(variant_config_path))\n        for variant in variant_config['variants']:\n            if not fuzzers or variant['name'] in fuzzers:\n                # Modify the config from the variants.yaml format to the\n                # format expected by a fuzzer config.\n                assert 'name' in variant, (\n                    'Missing name attribute for fuzzer variant in {}'.format(\n                        variant_config_path))\n                variant['variant_name'] = variant['name']\n                del variant['name']\n                variant['fuzzer'] = fuzzer\n                fuzzer_configs.append(variant)\n\n    return fuzzer_configs\n", "path": "common/fuzzer_utils.py"}], "after_files": [{"content": "# Copyright 2020 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Fuzzer helpers.\"\"\"\n\nimport importlib\nimport os\nimport re\nfrom typing import Optional\n\nfrom common import logs\nfrom common import utils\n\nDEFAULT_FUZZ_TARGET_NAME = 'fuzz-target'\nFUZZ_TARGET_SEARCH_STRING = b'LLVMFuzzerTestOneInput'\nVALID_FUZZER_REGEX = re.compile(r'^[A-Za-z0-9_]+$')\n\n\ndef get_fuzz_target_binary(search_directory: str,\n                           fuzz_target_name: str) -> Optional[str]:\n    \"\"\"Return target binary path.\"\"\"\n    if fuzz_target_name:\n        fuzz_target_binary = os.path.join(search_directory, fuzz_target_name)\n        if os.path.exists(fuzz_target_binary):\n            return fuzz_target_binary\n        return None\n\n    default_fuzz_target_binary = os.path.join(search_directory,\n                                              DEFAULT_FUZZ_TARGET_NAME)\n    if os.path.exists(default_fuzz_target_binary):\n        return default_fuzz_target_binary\n\n    for root, _, files in os.walk(search_directory):\n        if root == 'uninstrumented':\n            continue\n        for filename in files:\n            if filename.endswith('-uninstrumented'):\n                # Skip uninstrumented binaries (e.g. with QSYM).\n                continue\n\n            file_path = os.path.join(root, filename)\n            with open(file_path, 'rb') as file_handle:\n                if FUZZ_TARGET_SEARCH_STRING in file_handle.read():\n                    return file_path\n\n    return None\n\n\ndef validate(fuzzer):\n    \"\"\"Return True if |fuzzer| is a valid fuzzbench fuzzer.\"\"\"\n    # Although importing probably allows a subset of what the regex allows, use\n    # the regex anyway to be safe. The regex is enforcing that the fuzzer is a\n    # valid path for GCS or a linux system.\n    if VALID_FUZZER_REGEX.match(fuzzer) is None:\n        logs.error('%s does not conform to %s pattern.', fuzzer,\n                   VALID_FUZZER_REGEX.pattern)\n        return False\n\n    # Try importing the fuzzer module.\n    module_name = 'fuzzers.{}.fuzzer'.format(fuzzer)\n    try:\n        importlib.import_module(module_name)\n        return True\n    except Exception as error:  # pylint: disable=broad-except\n        logs.error('Encountered \"%s\" while trying to import %s.', error,\n                   module_name)\n        return False\n\n\ndef get_fuzzer_configs(fuzzers=None):\n    \"\"\"Returns the list of all fuzzers.\"\"\"\n    # Import it here to avoid yaml dependency in runner.\n    # pylint: disable=import-outside-toplevel\n    from common import yaml_utils\n\n    fuzzers_dir = os.path.join(utils.ROOT_DIR, 'fuzzers')\n    fuzzer_configs = []\n    for fuzzer in os.listdir(fuzzers_dir):\n        if not os.path.isfile(os.path.join(fuzzers_dir, fuzzer, 'fuzzer.py')):\n            continue\n        if fuzzer == 'coverage':\n            continue\n\n        if not fuzzers or fuzzer in fuzzers:\n            # Auto-generate the default configuration for each base fuzzer.\n            fuzzer_configs.append({'fuzzer': fuzzer})\n\n        variant_config_path = os.path.join(fuzzers_dir, fuzzer, 'variants.yaml')\n        if not os.path.isfile(variant_config_path):\n            continue\n\n        variant_config = yaml_utils.read(variant_config_path)\n        assert 'variants' in variant_config, (\n            'Missing \"variants\" section of {}'.format(variant_config_path))\n        for variant in variant_config['variants']:\n            if not fuzzers or variant['name'] in fuzzers:\n                # Modify the config from the variants.yaml format to the\n                # format expected by a fuzzer config.\n                assert 'name' in variant, (\n                    'Missing name attribute for fuzzer variant in {}'.format(\n                        variant_config_path))\n                variant['variant_name'] = variant['name']\n                del variant['name']\n                variant['fuzzer'] = fuzzer\n                fuzzer_configs.append(variant)\n\n    return fuzzer_configs\n", "path": "common/fuzzer_utils.py"}]}