Skip to content

FuzzIntrospector build steps#7162

Merged
oliverchang merged 22 commits intomasterfrom
FI_build_steps
Jan 31, 2022
Merged

FuzzIntrospector build steps#7162
oliverchang merged 22 commits intomasterfrom
FI_build_steps

Conversation

@Navidem
Copy link
Copy Markdown
Contributor

@Navidem Navidem commented Jan 20, 2022

Adds build steps for fuzz introspector to the coverage build.

Copy link
Copy Markdown
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much much better! Nice work

class Bucket: # pylint: disable=too-few-public-methods
"""Class representing the coverage GCS bucket."""
"""Class representing the GCS bucket."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should probably define a BUCKET_NAME = None here.
@oliverchang WDYR?
On the one hand not doing None makes incorrect implementations fail louder, on the other hand it seems too-dynamic and icky to do this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option would be to override init and use super.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the BUCKET_NAME = None was needed for lint.

introspector_enabled = False
if project.fuzzing_language in LANGUAGES_WITH_INTROSPECTOR_SUPPORT:
introspector_enabled = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... maybe do

else
introspector_enabled = False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got rid of this.

runner_image_name = build_project.get_runner_image_name(
base_images_project, config.test_image_suffix)
if introspector_enabled:
runner_image_name += ':introspector'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why are we using the tag for this instead of a different image name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of this as well. We can use :latest now.

upload_fuzzer_stats_url,
'html_report_url':
bucket.html_report_url,
os.path.join(bucket.html_report_url, 'index.html'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what's the right thing to do here, but for URLs I generally use posixpath.join instead of os.path.join
since os.path.join would break on Windows for URLs (it would use backslash: "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

LATEST_REPORT_INFO_CONTENT_TYPE))

if introspector_enabled:
coverage_url = bucket.html_report_url
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Don't put this in a variable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

config.test_image_suffix),
'args': [
'bash', '-c',
('sed -i s/base-builder/base-builder:introspector/g '
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what you can do to avoid this is the following
run the command:
docker tag gcr.io/oss-fuzz-base/base-builder:introspector gcr.io/oss-fuzz-base/base-builder:latest
and then you won't need sed.

Note that your technique and mine breaks if someone were to change the FROM line.
This happens sometimes when someone wants to use an older version of clang.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Do this instead of sed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

'bash', '-c',
('sed -i s/base-builder/base-builder:introspector/g '
f'oss-fuzz/projects/{project.name}/Dockerfile'
f' && cat oss-fuzz/projects/{project.name}/Dockerfile')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cat step shouldn't be necessary right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOPS! it was for debugging purpose.

'build',
'-t',
f'gcr.io/oss-fuzz/{project.name}',
'.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of using "." and dir, you can use docker's --file argument.

config.test_image_suffix),
'args': [
'bash', '-c',
('sed -i s/base-builder/base-builder:introspector/g '
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Do this instead of sed.

@Navidem
Copy link
Copy Markdown
Contributor Author

Navidem commented Jan 24, 2022

I have to fix test failures.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: delete these empty lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.



deploy_cloud_function request-introspector-build \
introspector_build \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fix indent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you forgot to push. I edited this file.


def introspector_build(event, context):
"""Entry point for cloud function to build introspector reports."""
request_introspector_build.request_introspector_build(event, context)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add this file too (request_introspector_build.py).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! done...

import request_introspector_build



Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tip: try not to make changes that aren't necessary for your PR, like deleting lines such as this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,58 @@
# Copyright 2022 Google Inc.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: LLC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

upload_fuzzer_stats_url,
'html_report_url':
bucket.html_report_url,
os.path.join(bucket.html_report_url, 'index.html'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

def get_fuzz_introspector_steps( # pylint: disable=too-many-locals, too-many-arguments, unused-argument
project_name, project_yaml_contents, dockerfile_lines, image_project,
base_images_project, config):
"""Return build steps of fuzz introspector for project"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the docstring should be in descriptive style acording to the style guide: https://google.github.io/styleguide/pyguide.html#383-functions-and-methods

e.g. "Returns build step" instead of "Return build step"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return steps


def download_coverage_data_steps(project_name, latest, bucket_name, testing):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to try to think of a way to share code with download_corpora_steps since it looks like this code was copied.

steps = []
fuzz_targets = _get_targets_list(project_name, testing)
if not fuzz_targets:
sys.stderr.write('No fuzz targets found for project "%s".\n' % project_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you log instead of writing to stderr please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other functions in build_lib.py are writing to stderr, too. Should we change them all?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh can leave for consistency. We can change them all another time.

Copy link
Copy Markdown
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looking close! Just some more minor comments.

Also, we need tests for the request_introspector_build part. In the interests of time, we can do this in another PR (please add a TODO) if you've manually tested this already.


coverage_report_latest = build_project.get_datetime_yesterday().strftime(
'%Y%m%d')
# TODO: debug
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

return datetime.datetime.now()


def get_datetime_yesterday():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than this, we could also try to figure out the actual latest uploaded report by looking at the bucket. Can leave this as a TODO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that is what we have to change later. For now I changed it to use the current date. It means it needs the coverage build have to finish before starting introspector build.

f'gcr.io/oss-fuzz/{project.name}',
'.',
],
'dir': f'oss-fuzz/projects/{project.name}',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use posixpath.join instead

Copy link
Copy Markdown
Contributor Author

@Navidem Navidem Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we use posixpath.join for URLs. Did you mean using os.path.join()?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use posixpath here, as the Cloud Build environment is posix. The environment this script runs may not be posix.

@oliverchang oliverchang merged commit 42880c1 into master Jan 31, 2022
@oliverchang oliverchang deleted the FI_build_steps branch January 31, 2022 00:56
DonggeLiu pushed a commit that referenced this pull request Feb 3, 2022
Adds build steps for fuzz introspector to the coverage build.
MartinPetkov pushed a commit to MartinPetkov/oss-fuzz that referenced this pull request Aug 15, 2022
Adds build steps for fuzz introspector to the coverage build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants