Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/fuzzing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Fuzzing

# spell-checker:ignore fuzzer

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
fuzz-build:
name: Build the fuzzers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Install `cargo-fuzz`
run: cargo install cargo-fuzz
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-fuzz-cache-key"
cache-directories: "fuzz/target"
- name: Run `cargo-fuzz build`
run: cargo +nightly fuzz build

fuzz-run:
needs: fuzz-build
name: Run the fuzzers
runs-on: ubuntu-latest
timeout-minutes: 5
env:
RUN_FOR: 60
strategy:
matrix:
test-target:
- { name: fuzz_ed, should_pass: true }
- { name: fuzz_normal, should_pass: true }
- { name: fuzz_patch, should_pass: true }
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Install `cargo-fuzz`
run: cargo install cargo-fuzz
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-fuzz-cache-key"
cache-directories: "fuzz/target"
- name: Restore Cached Corpus
uses: actions/cache/restore@v4
with:
key: corpus-cache-${{ matrix.test-target.name }}
path: |
fuzz/corpus/${{ matrix.test-target.name }}
- name: Run ${{ matrix.test-target.name }} for XX seconds
shell: bash
continue-on-error: ${{ !matrix.test-target.name.should_pass }}
run: |
cargo +nightly fuzz run ${{ matrix.test-target.name }} -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
- name: Save Corpus Cache
uses: actions/cache/save@v4
with:
key: corpus-cache-${{ matrix.test-target.name }}
path: |
fuzz/corpus/${{ matrix.test-target.name }}
11 changes: 9 additions & 2 deletions fuzz/fuzz_targets/fuzz_ed.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
use diffutils::{ed_diff, normal_diff, unified_diff};
use diffutilslib::ed_diff;
use diffutilslib::ed_diff::DiffError;
use std::fs::{self, File};
use std::io::Write;
use std::process::Command;

fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>, DiffError> {
let mut output = ed_diff::diff(expected, actual)?;
writeln!(&mut output, "w {filename}").unwrap();
Ok(output)
}

fuzz_target!(|x: (Vec<u8>, Vec<u8>)| {
let (mut from, mut to) = x;
from.push(b'\n');
Expand All @@ -30,7 +37,7 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>)| {
} else {
return;
}
let diff = ed_diff::diff_w(&from, &to, "target/fuzz.file").unwrap();
let diff = diff_w(&from, &to, "target/fuzz.file").unwrap();
File::create("target/fuzz.file.original")
.unwrap()
.write_all(&from)
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_normal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
use diffutils::{normal_diff, unified_diff};
use diffutilslib::normal_diff;

use std::fs::{self, File};
use std::io::Write;
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_patch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
use diffutils::{normal_diff, unified_diff};
use diffutilslib::unified_diff;
use std::fs::{self, File};
use std::io::Write;
use std::process::Command;
Expand Down