Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fuzzer to be run with OSS-Fuzz #772

Merged
merged 20 commits into from
Mar 3, 2021
Merged

Added fuzzer to be run with OSS-Fuzz #772

merged 20 commits into from
Mar 3, 2021

Conversation

DavidKorczynski
Copy link
Contributor

Adds a fuzzer as a step to integrating into OSS-Fuzz.

Cross-referencing

@Julian I now added more structure to it by way of Hypothesis and am happy to put more effort in. I think it would be nice to get it up and running on OSS-Fuzz though, so we can start to see when results happen.

@Zac-HD Thanks for your assistance in the other issue. Will keep digging into Hypothesis!

@codecov
Copy link

codecov bot commented Jan 21, 2021

Codecov Report

Merging #772 (d9b5ca8) into main (b4a3340) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #772   +/-   ##
=======================================
  Coverage   96.37%   96.37%           
=======================================
  Files          17       17           
  Lines        2703     2703           
  Branches      309      309           
=======================================
  Hits         2605     2605           
  Misses         79       79           
  Partials       19       19           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4a3340...d9b5ca8. Read the comment docs.

@Julian
Copy link
Member

Julian commented Jan 21, 2021

@Julian I now added more structure to it by way of Hypothesis and am happy to put more effort in. I think it would be nice to get it up and running on OSS-Fuzz though, so we can start to see when results happen.

Cool! So the idea here which I think I'm OK with is to get something here that we can run and iterate on without needing to touch the upstream OSS-Fuzz repo, right? I think to @Zac-HD's point what's here so far likely wouldn't "do" much utility wise but with some tweaks hopefully would. So we could just push forward and work on those tweaks.

I do think much as it might seem annoying, that we should address the coverage failure -- meaning, it would be good to have a "test" that executes the fuzzer for some extremely tiny amount, just so that we know any API changes don't suddenly silently break integration with OSS-Fuzz.

Does that make sense to you / seem like it'd be non-totally-terrible to do? The hardest part may be that module here which may need stubbing that's OSS-Fuzz specific? Let me know thoughts otherwise I can think myself about what that might look like, but yeah do think it'd be nice if somewhere locally here in CI we knew this script continued to function.

@DavidKorczynski
Copy link
Contributor Author

DavidKorczynski commented Jan 21, 2021

@Julian I do think much as it might seem annoying, that we should address the coverage failure -- meaning, it would be good to have a "test" that executes the fuzzer for some extremely tiny amount, just so that we know any API changes don't suddenly silently break integration with OSS-Fuzz.

Does that make sense to you / seem like it'd be non-totally-terrible to do? The hardest part may be that module here which may need stubbing that's OSS-Fuzz specific? Let me know thoughts otherwise I can think myself about what that might look like, but yeah do think it'd be nice if somewhere locally here in CI we knew this script continued to function.

I understand your concern although having integrated loads of projects into OSS-Fuzz it's a first to actually write tests that tests the fuzzers. How about doing the following approach - I added a main.yml file that integrates jsonschema into CI-fuzz, i.e. the fuzzer will be run for 600 seconds for every pull request. This might be a good approach to this? Let me know if not and I will then add a test.

@DavidKorczynski
Copy link
Contributor Author

@Julian Cool! So the idea here which I think I'm OK with is to get something here that we can run and iterate on without needing to touch the upstream OSS-Fuzz repo, right?

Yep, no iterations needed from you on OSS-Fuzz. Also, we are collaborating with the OSS-Fuzz folks so you can ping me whenever if you think there is something going that needs fixing in OSS-Fuzz and I will handle it for you. But by default you will not need to touch OSS-Fuzz.

@Julian
Copy link
Member

Julian commented Jan 21, 2021

I added a main.yml file that integrates jsonschema into CI-fuzz, i.e. the fuzzer will be run for 600 seconds for every pull request. This might be a good approach to this? Let me know if not and I will then add a test.

I think even if this were 2 seconds rather than 600 seconds that my concern would be addressed. It's just "make sure the thing runs" any time someone makes a change to it.

@DavidKorczynski
Copy link
Contributor Author

DavidKorczynski commented Jan 21, 2021

The reason I set 600 seconds is because OSS-Fuzz sets it as a minimum (https://google.github.io/oss-fuzz/getting-started/continuous-integration/#integrating-into-your-repository)

@Julian
Copy link
Member

Julian commented Jan 21, 2021

The reason I set 600 seconds is because OSS-Fuzz sets it as a minimum (https://google.github.io/oss-fuzz/getting-started/continuous-integration/#integrating-into-your-repository)

It's not really a minimum, that's the docs saying any less than that and it's not very useful for fuzzing not that it will fail the build or anything -- let's set it to 30 seconds I think.

Looks like it's failing now though for some config reason?

@DavidKorczynski
Copy link
Contributor Author

Looks like it's failing now though for some config reason?

I recon this is because the project is not ready integrated in OSS-Fuzz (we are waiting for this to merge)

@Julian
Copy link
Member

Julian commented Jan 21, 2021

Ah fair enough. Can you maybe make that job not fail the build then (that might be reasonable even going forward perhaps)?

After that sounding like we're close to merge.

@DavidKorczynski
Copy link
Contributor Author

Ah fair enough. Can you maybe make that job not fail the build then (that might be reasonable even going forward perhaps)?

After that sounding like we're close to merge.

Could you clarify on this one - am not sure I understand (this is the first time I integrate a CI job).

Do you mean make it not fail by merging things in OSS-Fuzz, or do you mean not fail by changing something in the main.yml file? I put in a continue-on-error: true for the fuzzing job, is this perhaps what you were looking for?

@DavidKorczynski
Copy link
Contributor Author

I think I got a solution you were looking for now @Julian - now the CIFuzz job will exit with success in case the build step fails.

@Julian
Copy link
Member

Julian commented Jan 22, 2021

Hooray. Will have a close look in the morning when I've got a clean mind but think that's perfect!

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

One nice way to ensure everything is covered is to run the fuzz harness as a test function! Specifically:

  • Rename the file as e.g. test_foo_fuzz.py, so that pytest collects it;
  • Adjust the glob pattern in the OSS-Fuzz config to detect *fuzz.py instead of fuzz_*.py
  • Move import atheris into the if __name__ == "__main__": block, so that it's a fuzz-time but not a test-time dependency

And then it'll be covered as expected (modulo perhaps a coverage pragma on the __name__ branch...)

jsonschema/tests/fuzz_validate.py Outdated Show resolved Hide resolved
jsonschema/tests/fuzz_validate.py Outdated Show resolved Hide resolved
@Julian
Copy link
Member

Julian commented Jan 30, 2021

@DavidKorczynski apologies for the delay here, have been dealing with some other stuff first, but hopefully will get to merging this by the end of the weekend.

@DavidKorczynski
Copy link
Contributor Author

No problem @Julian - please take your time and handle this when it makes sense to you. There is no stress from my side.

Julian added 3 commits March 2, 2021 18:42
* main:
  Reskip the PyPy-on-Windows tests.
  Try the Twisted prerelease, which hopefully obviates installing IOCP.
  No, don't use venv.
  Fix test to windows path matching
  Test via PyPy3.7
  Unskip most of the skipped windows builds.
  Update pre-commit.
Julian added 5 commits March 2, 2021 19:02
Run only against main for now, save some time on PRs.
Hypothesis isn't a current testing dependency, so as this
was before (where it was named test_* and discovered by the
test runner) there are CI failures for the normal test suite
run.

In the future hypothesis will likely become a normal testing
dependency and then we can run this as well, but for now,
only run it in the CIFuzz job.
@Julian
Copy link
Member

Julian commented Mar 3, 2021

@DavidKorczynski apologies here that this slipped, but I'm likely about to merge as soon as CI passes (which I put some minor changes in for).

I did re-rename this back to fuzz_* rather than being prefixed with test_ even though I agree that's a good thing in the long term, but for now hypothesis isn't a testing dependency so it was failing the normal CI run when that module was imported, and rather than bother to futz with installing hypothesis to be able to import that file, I just moved it back for now.

You'll obviously see when/if I merge in a bit after I see the build go green.

@Julian Julian merged commit b1772a1 into python-jsonschema:main Mar 3, 2021
@DavidKorczynski
Copy link
Contributor Author

Wohoooo - we got it done :)! google/oss-fuzz#4996

Thanks @Zac-HD for the input and thanks @Julian for getting it merged in.

@Julian
Copy link
Member

Julian commented Mar 5, 2021

Thank you!

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