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

Basic fuzzing harness #126

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Basic fuzzing harness #126

wants to merge 13 commits into from

Conversation

jmcph4
Copy link

@jmcph4 jmcph4 commented Nov 15, 2024

This PR adds a basic fuzzing harness to Solar using cargo-fuzz, a popular frontend to the libfuzzer fuzzing engine.

Specifically, this PR contains the following cases:

  • run_compiler_args, a (reasonably close to) end-to-end case for the entire compiler
  • parsing_context_parse_and_resolve, specifically targeting just parsing and semantic analysis
  • canonicalize, targeting path canonicalisation (low-hanging and likely uninteresting, but added for posterity)

The intent (and expectation) is that this PR will allow for easy extension and expansion of fuzzing cases as development of the compiler progresses.

@jmcph4
Copy link
Author

jmcph4 commented Nov 15, 2024

Would appreciate a double check of the parsing_context_parse_and_resolve case to make sure that this is an acceptable usage of that API (so that this fuzzing case actually hits an acceptable scenario).

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Thanks a lot! A few comments

Copy link
Member

Choose a reason for hiding this comment

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

This target is redundant since the canonicalize function is implemented using the standard library, and it's also coming from dunce, not implemented here.


let _ = sess.enter(|| -> solar_interface::Result<()> {
let mut pcx = solar_sema::ParsingContext::new(&sess);
pcx.load_file(&path).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

We can avoid the temp file by using add_file with a SourceFile created in memory, like so:

let Ok(data) = std::str::::from_utf8(data) else {
    return Ok(());
};
let Ok(file) = sess.source_map().new_dummy_source_file("fuzz".into(), data.to_string()) else {
    return;
};
pcx.add_file(file);

solar-parse = { path = "../crates/parse" }
solar-interface = { path = "../crates/interface" }
solar-sema = { path = "../crates/sema" }
solar-cli = { path = "../crates/cli" }
Copy link
Member

Choose a reason for hiding this comment

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

Use .workspace = true instead for these dependencies

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.

2 participants