Fuzz the expr command#4642
Merged
sylvestre merged 1 commit intouutils:mainfrom Sep 26, 2023
sylvestre:fuzz-expr
Merged
Conversation
Merged
This was referenced Sep 24, 2023
sylvestre
commented
Sep 24, 2023
| cd fuzz | ||
| cargo +nightly fuzz run fuzz_test -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0 | ||
| - name: Run fuzz_expr for XX seconds | ||
| continue-on-error: true |
Contributor
Author
Contributor
Author
|
as expected, fails quickly: |
cakebaker
reviewed
Sep 26, 2023
Comment on lines
+44
to
+65
| fn generate_random_string(max_length: usize) -> String { | ||
| let mut rng = rand::thread_rng(); | ||
| let valid_utf8: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | ||
| .chars() | ||
| .collect(); | ||
| let invalid_utf8 = [0xC3, 0x28]; // Invalid UTF-8 sequence | ||
| let mut result = String::new(); | ||
|
|
||
| for _ in 0..rng.gen_range(1..=max_length) { | ||
| if rng.gen_bool(0.9) { | ||
| let ch = valid_utf8.choose(&mut rng).unwrap(); | ||
| result.push(*ch); | ||
| } else { | ||
| let ch = invalid_utf8.choose(&mut rng).unwrap(); | ||
| if let Some(c) = char::from_u32(*ch as u32) { | ||
| result.push(c); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| result | ||
| } |
Contributor
There was a problem hiding this comment.
This function looks like a candidate for fuzz_common.rs as it is used in fuzz_test.rs, too.
cakebaker
reviewed
Sep 26, 2023
| .to_string() | ||
| .trim() | ||
| .to_owned(); | ||
|
|
Contributor
There was a problem hiding this comment.
Lines 111 - 156 also look like a candidate for fuzz_common.rs, they seem to be identical to the code in fuzz_test.rs.
cakebaker
approved these changes
Sep 26, 2023
Contributor
cakebaker
left a comment
There was a problem hiding this comment.
Looks good :) My suggestions are probably more something for a future PR.
Contributor
Author
|
agreed, it was part of my place to refactor some of the code :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on:
#4641