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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- fuzz_json_de
- fuzz_cbor_decode
- fuzz_cbor_roundtrip
- fuzz_object_ops
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ path = "fuzz_targets/fuzz_cbor_roundtrip.rs"
test = false
doc = false
bench = false

[[bin]]
name = "fuzz_object_ops"
path = "fuzz_targets/fuzz_object_ops.rs"
test = false
doc = false
bench = false
52 changes: 52 additions & 0 deletions fuzz/fuzz_targets/fuzz_object_ops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#![no_main]

use arbitrary::Arbitrary;
use ijson::{IObject, IValue};
use libfuzzer_sys::fuzz_target;
use std::collections::HashMap;

// Small key space (u8 -> "k{n}") so op sequences repeatedly hit the same keys,
// reliably crossing the small-object table threshold in both directions and
// forcing hash collisions / Robin-Hood displacement on the u32 table.
#[derive(Arbitrary, Debug)]
enum Op {
Insert(u8, u64),
Remove(u8),
Get(u8),
}

fuzz_target!(|ops: Vec<Op>| {
let mut obj = IObject::new();
let mut oracle: HashMap<u8, u64> = HashMap::new();

for op in ops {
match op {
Op::Insert(id, v) => {
let k = format!("k{id}");
// insert() only errors on OOM / 2^30 overflow; neither is reachable here.
let prev = obj
.insert(k.as_str(), IValue::from(v))
.unwrap()
.and_then(|old| old.to_u64());
assert_eq!(prev, oracle.insert(id, v));
}
Op::Remove(id) => {
let k = format!("k{id}");
let removed = obj.remove(k.as_str()).and_then(|v| v.to_u64());
assert_eq!(removed, oracle.remove(&id));
}
Op::Get(id) => {
let k = format!("k{id}");
let got = obj.get(k.as_str()).and_then(|v| v.to_u64());
assert_eq!(got, oracle.get(&id).copied());
}
}
assert_eq!(obj.len() as usize, oracle.len());
}

// Final agreement: every oracle key present with the right value.
for (id, v) in &oracle {
let k = format!("k{id}");
assert_eq!(obj.get(k.as_str()).and_then(|x| x.to_u64()), Some(*v));
}
});
Loading
Loading