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

perf(fuzz): Improves code coverage of fuzzers #554

Merged
merged 2 commits into from
Feb 20, 2023

Conversation

silvergasp
Copy link
Contributor

Updates fuzz target to include;

  • A round trip writer
  • A slice reader
  • Pretty printing, debug and display code

@silvergasp silvergasp marked this pull request as ready for review February 16, 2023 17:06
Updates fuzz target to include;
- A round trip writer
- A slice reader
- Pretty printing, debug and display code
@Mingun
Copy link
Collaborator

Mingun commented Feb 17, 2023

I correctly understand, that the purpose of this PR is to call as much methods as we can for fuzzing them? Would it be valuable to test each method in it's own fuzz_target! or that would be an overkill?

I also noted, that we do not run fuzzing in our CI. Could you add a job for that to the workflow?

@silvergasp
Copy link
Contributor Author

Yeah, that's right, this fuzz harness is just calling as much functionality as possible to find ways that it could crash. . I think that there could be some value in splitting this fuzz harness up into 1 or more logical units. But I think it'll be impractical to do it as 1 function per fuzz_target!. This is mostly because there is some nested logic, e.g. in order to reach some functions you first need to match on a result etc.

There are other ways of fuzzing, for example, you can do property-based fuzz testing. In the context of quickxml this might look like generate_arbitrary_xml->parse_xml then assert that the parsed xml is identical to the generated xml. I'd be happy to open another PR doing this, although this would required some more intrusive changes to quick-xml, namely implementing arbitrary for the quick-xml types.

I'd be happy add this to the CI. As quick-xml is already integrated with google/oss-fuzz might I suggest adding an oss-fuzz specific github action instead?

@Mingun
Copy link
Collaborator

Mingun commented Feb 18, 2023

Ok. I just have very limited knowledge about best practices in fuzzing, so I want to hear suggestions from more advanced users. Then the current implementation is fine.

I'd be happy add this to the CI. As quick-xml is already integrated with google/oss-fuzz might I suggest adding an oss-fuzz specific github action instead?

Seems reasonable. Do it.

I'd be happy to open another PR doing this, although this would required some more intrusive changes to quick-xml, namely implementing arbitrary for the quick-xml types.

I think it is reasonable change, just make new dependency optional and run fuzzing with a special feature enabled.

@silvergasp
Copy link
Contributor Author

I'd be happy add this to the CI. As quick-xml is already integrated with google/oss-fuzz might I suggest adding an oss-fuzz specific github action instead?

Seems reasonable. Do it.

Done

.github/workflows/cifuzz.yml Outdated Show resolved Hide resolved
.github/workflows/cifuzz.yml Outdated Show resolved Hide resolved
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a normal practice to depend on master for that job? The tagged version would be better, as I think (but I maybe wrong)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is normal practice yeah. Although now that you mention it, it does seem a little strange that this is "normal practice".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +22 to +24
with:
name: artifacts
path: ./out/artifacts
Copy link
Collaborator

Choose a reason for hiding this comment

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

That name / path has some concrete meaning for the job? Maybe better to name them crashes if the concrete name do not matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it has a specific meaning in the context of fuzzing. Artifacts encompass more than just crashes. e.g. crashes, out-of-memory errors, timeouts (e.g. triggered by an infinite loop) etc. I think even if we could change the name of this directory (which oss-fuzz won't like), it wouldn't make sense to as some of the outputs here aren't necessarily just crashes. There is some documentation for artifacts here.

@codecov-commenter
Copy link

Codecov Report

Merging #554 (912e545) into master (221b57d) will decrease coverage by 0.11%.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #554      +/-   ##
==========================================
- Coverage   61.25%   61.15%   -0.11%     
==========================================
  Files          32       33       +1     
  Lines       15654    15670      +16     
==========================================
- Hits         9589     9583       -6     
- Misses       6065     6087      +22     
Flag Coverage Δ
unittests 61.15% <ø> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/lib.rs 13.31% <0.00%> (-0.07%) ⬇️
src/de/mod.rs 56.14% <0.00%> (-0.06%) ⬇️
src/escapei.rs 13.24% <0.00%> (-0.06%) ⬇️
src/reader/mod.rs 94.93% <0.00%> (-0.02%) ⬇️
src/de/simple_type.rs 93.65% <0.00%> (ø)
src/reader/ns_reader.rs 63.71% <0.00%> (ø)
src/events/attributes.rs 93.56% <0.00%> (ø)
examples/nested_readers.rs 0.00% <0.00%> (ø)
src/reader/slice_reader.rs 100.00% <0.00%> (ø)
examples/custom_entities.rs 0.00% <0.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dralley dralley merged commit e1e092b into tafia:master Feb 20, 2023
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.

4 participants