MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / fuzz_random_payloads

Function fuzz_random_payloads

nodedb-query/src/msgpack_scan/index.rs:229–253  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

227 /// Deterministic random byte sequences — FieldIndex::build must never panic.
228 #[test]
229 fn fuzz_random_payloads() {
230 let mut state: u64 = 0xabad1dea_deadc0de;
231 let next = |s: &mut u64| -> u8 {
232 *s = s
233 .wrapping_mul(6364136223846793005)
234 .wrapping_add(1442695040888963407);
235 (*s >> 33) as u8
236 };
237
238 let mut buf = [0u8; 128];
239 for _ in 0..1000 {
240 let len = (next(&mut state) as usize % 128) + 1;
241 for b in buf[..len].iter_mut() {
242 *b = next(&mut state);
243 }
244 let slice = &buf[..len];
245 let idx = FieldIndex::build(slice, 0);
246 // If build succeeded, get() on the result must not panic either.
247 if let Some(ref idx) = idx {
248 let _ = idx.get("any_key");
249 let _ = idx.len();
250 let _ = idx.is_empty();
251 }
252 }
253 }
254
255 /// Adversarial map headers — FieldIndex::build must return None.
256 #[test]

Callers

nothing calls this directly

Calls 4

iter_mutMethod · 0.80
getMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected