-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fuzzy tests #61
Comments
As described in rust-lang#61, fuzz testing some parts of this would be ~~fun~~ helpful. So, I started with the most trivial fuzzer I could think of: Put random stuff into File::parse and see what happens. To speed things up, I also did cp src/**/*.rs fuzz/corpus/parser/ in the `crates/libsyntax2/` directory (running the fuzzer once will generate the necessary directories).
Made a small PR with the most trivial fuzzer: #63. With the rs files from the libsyntax2 crate as corpus it quickly goes up to a coverage of 20199 (probably code paths but I don't know libfuzzer well enough; it's a high number compared to other fuzz targets, though). Aaaaan it even found a crash! https://gist.github.com/killercup/a0be6701333a635de9dec6cffc89aedb |
Two other interesting approaches: vegard/prog-fuzz@c80b1a7 and creating edits from commits |
That's a good sign! Today I've made sure that parser deals with rust-lang/rust, with fail-tests and all, so this failure must be non-trivial. I'll write a fix shortly with a description of how to fix these things: I expect this won't be the sole fuzzing error :)
As a bonus objective, I think it makes sense to add |
Oh yes it most definitely is a non-trivial failure, it took the fuzzer almost 3 minutes to find – compared to most other projects where the first failures show up after 3 seconds! ;) This is just the very first stab at things! I think I'll have a few hours to kill waiting at an airport tomorrow and might just integrate this with you tools crate and also throw other fuzzers at it. I've been meaning to make fuzzer definitions more generic anyway. And maybe after I've understood how to use libsyntax2 I can also use it to write a tool to auto-generate fuzzers for all functions that take a |
@killercup is it running the parser with debug-assertions on? One check (
Yep, I think libsyntax2, even in its current state, might be a good tool for the job (although right now |
63: Add trivial fuzzer for parser r=matklad a=killercup As described in #61, fuzz testing some parts of this would be ~~fun~~ helpful. So, I started with the most trivial fuzzer I could think of: Put random stuff into File::parse and see what happens. To speed things up, I also did cp src/**/*.rs fuzz/corpus/parser/ in the `crates/libsyntax2/` directory (running the fuzzer once will generate the necessary directories). Co-authored-by: Pascal Hertleif <killercup@gmail.com>
Oh, one more useful thing to do would be to add a short note to readme, explaning how to actually run this thing :) |
Ah, the delicious taste of dog food: I've copy-pasted your example as a test, and of course the plugin is now half-broken, because the indexing thread panics :D |
Added a fix with a long explanation of what actually is going on: #64 (second commit msg). If your fuzzers find more errors like these, you now know how to fix 'em! |
Totally forgot to answer this one! Yes:
And good point. I'll also run it in release to see if there is a unknown dependency on this somewhere (or a things that fails differently without overflow checks)! Edit: Yes, it also crashes with |
I've refactored code a bit, so that for fuzzing we always do that block check, even in release mode: |
Cool! When using `cargo fuzz`, it'll also pass `--cfg fuzzing` FYI
… Am 09.09.2018 um 11:10 schrieb Aleksey Kladov ***@***.***>:
. I'll also run it in release to see if there is a unknown dependency on this somewhere (or a things that fails differently without overflow checks)!
I've refactored code a bit, so that for fuzzing we always do that block check, even in release mode:
ba4a697
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
BTW, I am seeing the same |
Ran the fuzzer and found this: https://gist.github.com/YaLTeR/2d0c734a0cca830e136a59af3891f0b2 EDIT: and another one, although this contains |
Thanks! First one fixed in b6f8037. Letme take a look at the second one... EDIT: the second one is actually the same. It's not an |
I think the current action on this is just to run these every few weeks for a little bit to see if there's any code which can trigger a panic. I wonder if there's any neat way to remind us of this automatically - any ideas? |
A travis cron job? |
So yeah, there are two bits I want to add to the current setup to close the issue
A further improvement would be a high-level fuzzing, on the |
393: Add a fuzzing subcommand r=matklad a=DJMcNab Part of #61 (comment). Co-authored-by: DJMcNab <36049421+djmcnab@users.noreply.github.com>
Only cron job is left. Here are the docs: https://docs.travis-ci.com/user/cron-jobs/. |
Left it running overnight; no crashes yet :)
|
Hm, travis cron jobs are not really meant for long-running tasks. Is there a maximum time we want to run this? I would recommend a service such as oss-fuzz: We'd need to apply, though. |
Yeah, that's what I had in mind: limit fuzzing time by, say, five minutes every nigh. We've recently added some extra time consuming checks on nightly.
My gut feeling is that, at this stage, fuzzing would add relatively little benefit. So I'd rather avoid integrating with services besides the ones we already have. |
we have some fuzzing tests set up, we don't have automated fuzzing on CI, but, given the number of known bugs, I don't think it's worthwhile to invest time into this at this point. |
Just for the record, I have fed rust-lang/glacier and rust-lang/rust + around 30% of random files contained in the history of rust-lang/rust into #16288 I can do mutation-based fuzzing based on randomly mutated (using tree-splicer) rust files using https://github.com/matthiaskrgr/icemaker/ if anyone is interested :) |
There are several things that parser self-checks for during parsing:
We need to fuzz/property test the parser to verify that this does not happen in practice.
To that end, we need to implement:
The text was updated successfully, but these errors were encountered: