From 21d29a4cf6d3523fc32ab127e3e2e6228996e66f Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Thu, 7 May 2026 13:42:35 +0000 Subject: [PATCH] Add fuzing for Key CRDT (#1444) This has duplicated changes with #1442 that will likely conflict and need rebase. Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1444 Reviewed-by: Alex --- fuzz/Cargo.toml | 7 ++++++ fuzz/fuzz_targets/key_crdt.rs | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 fuzz/fuzz_targets/key_crdt.rs diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 3a6f4973..1c3c26d8 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -50,3 +50,10 @@ path = "fuzz_targets/admin_api_token_crdt.rs" test = false doc = false bench = false + +[[bin]] +name = "key_crdt" +path = "fuzz_targets/key_crdt.rs" +test = false +doc = false +bench = false diff --git a/fuzz/fuzz_targets/key_crdt.rs b/fuzz/fuzz_targets/key_crdt.rs new file mode 100644 index 00000000..0c7b9d07 --- /dev/null +++ b/fuzz/fuzz_targets/key_crdt.rs @@ -0,0 +1,43 @@ +#![no_main] + +use garage_fuzz::check_crdt_laws; +use garage_model::key_table::{Key, KeyParams}; +use garage_model::permission::BucketKeyPerm; +use garage_util::crdt; +use garage_util::data::Uuid; +use libfuzzer_sys::fuzz_target; + +type Input = ( + bool, + crdt::Lww, + crdt::Lww>, + crdt::Lww, + crdt::Map, + crdt::LwwMap>, +); + +fn make(input: Input) -> Key { + let (deleted, name, expiration, allow_create_bucket, authorized_buckets, local_aliases) = input; + let state = if deleted { + crdt::Deletable::Deleted + } else { + crdt::Deletable::present(KeyParams { + created: None, + secret_key: String::new(), + name, + expiration, + allow_create_bucket, + authorized_buckets, + local_aliases, + }) + }; + Key { + key_id: String::new(), + state, + } +} + +fuzz_target!(|inputs: (Input, Input, Input)| { + let (a, b, c) = inputs; + check_crdt_laws(make(a), make(b), make(c)); +});