예제 #1
0
    def download_latest_build(self):
        """Downloads the latest OSS-Fuzz build from GCS.

    Returns:
      A path to where the OSS-Fuzz build was stored, or None if it wasn't.
    """
        if os.path.exists(self.workspace.clusterfuzz_build):
            # This function can be called multiple times, don't download the build
            # again.
            return self.workspace.clusterfuzz_build

        os.makedirs(self.workspace.clusterfuzz_build, exist_ok=True)

        latest_build_name = self.get_latest_build_name()
        if not latest_build_name:
            return None

        oss_fuzz_build_url = utils.url_join(utils.GCS_BASE_URL,
                                            self.CLUSTERFUZZ_BUILDS,
                                            self.config.project_name,
                                            latest_build_name)
        if http_utils.download_and_unpack_zip(
                oss_fuzz_build_url, self.workspace.clusterfuzz_build):
            return self.workspace.clusterfuzz_build

        return None
예제 #2
0
    def download_latest_build(self):
        """Downloads the latest OSS-Fuzz build from GCS.

    Returns:
      A path to where the OSS-Fuzz build was stored, or None if it wasn't.
    """
        if os.path.exists(self.workspace.clusterfuzz_build):
            # This function can be called multiple times, don't download the build
            # again.
            return self.workspace.clusterfuzz_build

        _make_empty_dir_if_nonexistent(self.workspace.clusterfuzz_build)

        latest_build_name = self.get_latest_build_name()
        if not latest_build_name:
            return None

        logging.info('Downloading latest build.')
        oss_fuzz_build_url = utils.url_join(utils.GCS_BASE_URL,
                                            self.CLUSTERFUZZ_BUILDS,
                                            self.config.oss_fuzz_project_name,
                                            latest_build_name)
        if http_utils.download_and_unpack_zip(
                oss_fuzz_build_url, self.workspace.clusterfuzz_build):
            logging.info('Done downloading latest build.')
            return self.workspace.clusterfuzz_build

        return None
예제 #3
0
  def download_corpus(self, target_name, parent_dir):
    """Downloads the latest OSS-Fuzz corpus for the target.

    Returns:
      The local path to to corpus or None if download failed.
    """
    corpus_dir = self.get_target_corpus_dir(target_name, parent_dir)

    os.makedirs(corpus_dir, exist_ok=True)
    # TODO(metzman): Clean up this code.
    project_qualified_fuzz_target_name = target_name
    qualified_name_prefix = self.config.project_name + '_'

    if not target_name.startswith(qualified_name_prefix):
      project_qualified_fuzz_target_name = qualified_name_prefix + target_name

    corpus_url = (f'{utils.GCS_BASE_URL}{self.config.project_name}'
                  '-backup.clusterfuzz-external.appspot.com/corpus/'
                  f'libFuzzer/{project_qualified_fuzz_target_name}/'
                  f'{self.CORPUS_ZIP_NAME}')

    if http_utils.download_and_unpack_zip(corpus_url, corpus_dir):
      return corpus_dir

    return None
예제 #4
0
 def _download_artifact(self, name, dst_directory):
   """Downloads artifact with |name| to |dst_directory|."""
   artifact = self._find_artifact(name)
   if not artifact:
     logging.warning('Could not download artifact: %s.', name)
     return artifact
   download_url = artifact['archive_download_url']
   return http_utils.download_and_unpack_zip(
       download_url, dst_directory, headers=self.github_api_http_headers)
예제 #5
0
 def _raw_download_artifact(self, name, dst_directory):
     """Downloads the artifact with |name| to |dst_directory|. Returns True on
 success. Does not do any untarring or adding prefix to |name|."""
     artifact = self._find_artifact(name)
     if not artifact:
         logging.warning('Could not find artifact: %s.', name)
         return False
     download_url = artifact['archive_download_url']
     return http_utils.download_and_unpack_zip(
         download_url, dst_directory, headers=self.github_api_http_headers)
예제 #6
0
    def download_corpus(self, target_name):
        """Downloads the latest OSS-Fuzz corpus for the target.

    Returns:
      The local path to to corpus or None if download failed.
    """
        corpus_dir = self.make_empty_corpus_dir(target_name)
        project_qualified_fuzz_target_name = target_name
        qualified_name_prefix = self.config.project_name + '_'
        if not target_name.startswith(qualified_name_prefix):
            project_qualified_fuzz_target_name = qualified_name_prefix + target_name

        corpus_url = (f'{utils.GCS_BASE_URL}{self.config.project_name}'
                      '-backup.clusterfuzz-external.appspot.com/corpus/'
                      f'libFuzzer/{project_qualified_fuzz_target_name}/'
                      f'{self.CORPUS_ZIP_NAME}')

        if not http_utils.download_and_unpack_zip(corpus_url, corpus_dir):
            logging.warning('Failed to download corpus for %s.', target_name)
        return corpus_dir
예제 #7
0
 def test_bad_zip_download(self, _):
     """Tests download_and_unpack_zip returns none when a bad zip is passed."""
     self.fs.create_file('/url_tmp.zip', contents='Test file.')
     self.assertFalse(
         http_utils.download_and_unpack_zip('/not/a/real/url',
                                            '/extract-directory'))