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
28 changes: 28 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Fuzz"

on:
pull_request:
branches: [main]

jobs:
fuzz:
name: Fuzz smoke test (10s/target)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v16
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- uses: actions/checkout@v4
- name: Cache fuzz build artifacts
uses: actions/cache@v4
with:
path: fuzz/target
key: fuzz-${{ runner.os }}-${{ hashFiles('fuzz/Cargo.lock', 'rust-toolchain.toml') }}
restore-keys: |
fuzz-${{ runner.os }}-
- name: Run fuzz targets
env:
FUZZ_SECONDS: 10
run: nix run .#fuzz
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ sqlx-prepare:
# `nix run .#fuzz` and the Concourse `fuzz` job. Auto-discovers targets via
# `cargo fuzz list`; runs them for $(FUZZ_TIME)s. Corpus in fuzz/corpus/ (gitignored).
fuzz:
FUZZ_SECONDS=$(FUZZ_TIME) bash ci/vendor/tasks/fuzz.sh
SQLX_OFFLINE=true FUZZ_SECONDS=$(FUZZ_TIME) bash ci/vendor/tasks/fuzz.sh
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
# — no Postgres. FUZZ_SECONDS etc. are passed through the environment.
fuzz-runner = pkgs.writeShellScriptBin "fuzz" ''
set -e
export SQLX_OFFLINE=true
export PATH="${pkgs.lib.makeBinPath [
rustToolchain
pkgs.cargo-fuzz
Expand Down
22 changes: 11 additions & 11 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion fuzz/fuzz_targets/fuzz_decode_persistent_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use libfuzzer_sys::fuzz_target;

use chrono::Utc;
use obix::out::OutboxEventId;
use obix::{EventSequence, UndecodableEventError, decode_persistent_event};
use obix::{CommitGroupId, EventSequence, UndecodableEventError, decode_persistent_event};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand Down Expand Up @@ -58,13 +58,15 @@ fuzz_target!(|data: &[u8]| {
let id = OutboxEventId::from(Uuid::nil());
let sequence = 0u64;
let recorded_at = Utc::now();
let commit_group = CommitGroupId::from(0i64);

match decode_persistent_event::<FuzzPayload>(
id,
sequence,
recorded_at,
None,
payload.clone(),
commit_group,
) {
Ok(event) => {
if must_be_ok_with_none {
Expand All @@ -86,13 +88,15 @@ fuzz_target!(|data: &[u8]| {
assert_eq!(event.id, id);
assert_eq!(u64::from(event.sequence), sequence);
assert_eq!(event.recorded_at, recorded_at);
assert_eq!(event.commit_group, commit_group);
assert!(event.tracing_context.is_none());
}
Err(UndecodableEventError {
id: err_id,
sequence: err_seq,
recorded_at: err_ts,
failure,
commit_group: err_cg,
}) => {
// `None` can never be undecodable — that's the placeholder path.
let raw = payload
Expand All @@ -107,6 +111,7 @@ fuzz_target!(|data: &[u8]| {
assert_eq!(err_id, id);
assert_eq!(err_seq, EventSequence::from(sequence));
assert_eq!(err_ts, recorded_at);
assert_eq!(err_cg, commit_group);
}
}
});
Loading