This increases performance by 4x while reducing kernel load to not being present at all, down from 90%/nearly 1 CPU.
Unified · Split
| @@ -11,7 +11,7 @@ cargo-fuzz = true · 10 unmodified lines | |||
| 11 | anyhow = "1.0.76" | 11 | anyhow = "1.0.76" |
| 12 | arbitrary = { version = "1.3.2", features = ["derive"] } | 12 | arbitrary = { version = "1.3.2", features = ["derive"] } |
| 13 | libfuzzer-sys = "0.4" | 13 | libfuzzer-sys = "0.4" |
| 14 | tempfile = "3.8.1" | 14 | memmap2 = "0.9.0" |
| 15 | 15 | ||
| 16 | [dependencies.gix-commitgraph] | 16 | [dependencies.gix-commitgraph] |
| 17 | path = ".." | 17 | path = ".." |
| @@ -1,17 +1,17 @@ | |||
| 1 | #![no_main] | 1 | #![no_main] |
| 2 | 2 | ||
| 3 | use anyhow::Result; | 3 | use anyhow::Result; |
| 4 | use arbitrary::Arbitrary; | ||
| 5 | use gix_commitgraph::File; | 4 | use gix_commitgraph::File; |
| 6 | use libfuzzer_sys::fuzz_target; | 5 | use libfuzzer_sys::fuzz_target; |
| 7 | use std::fs; | ||
| 8 | use std::hint::black_box; | 6 | use std::hint::black_box; |
| 9 | use tempfile::NamedTempFile; | ||
| 10 | 7 | ||
| 11 | fn fuzz(data: &[u8]) -> Result<()> { | 8 | fn fuzz(data: &[u8]) -> Result<()> { |
| 12 | let named_temp_file = NamedTempFile::new()?; | 9 | let data = { |
| 13 | fs::write(named_temp_file.path(), data).expect("Unable to write fuzzed file"); | 10 | let mut d = memmap2::MmapMut::map_anon(data.len())?; |
| 14 | let file = File::try_from(named_temp_file.path())?; | 11 | d.copy_from_slice(data); |
| 12 | d.make_read_only()? | ||
| 13 | }; | ||
| 14 | let file = File::new(data, "does not matter".into())?; | ||
| 15 | 15 | ||
| 16 | _ = black_box(file.iter_base_graph_ids().count()); | 16 | _ = black_box(file.iter_base_graph_ids().count()); |
| 17 | _ = black_box(file.iter_commits().count()); | 17 | _ = black_box(file.iter_commits().count()); |