Initial import: ICE-NET research docs and Rust workspace (v0.4)
Some checks failed
rust-ci / checks (push) Has been cancelled
Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
This commit is contained in:
commit
2e61688eb3
141 changed files with 13993 additions and 0 deletions
60
workspace/crates/icenet-wire/tests/fuzz.rs
Normal file
60
workspace/crates/icenet-wire/tests/fuzz.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//! Deterministic parser smoke-fuzz: random bytes must never panic.
|
||||
use icenet_core::{ServiceId, TrafficClass};
|
||||
use icenet_wire::{Frame, FrameError, MAX_PAYLOAD_BYTES, decode, encode};
|
||||
|
||||
#[test]
|
||||
fn random_bytes_never_panic() {
|
||||
let mut state = 0x9e37_79b9_7f4a_7c15_u64;
|
||||
for _ in 0..10_000 {
|
||||
state = next(state);
|
||||
let length = usize::try_from(state % 96).expect("small length");
|
||||
let mut bytes = Vec::with_capacity(length);
|
||||
for _ in 0..length {
|
||||
state = next(state);
|
||||
bytes.push((state >> 24) as u8);
|
||||
}
|
||||
if let Ok(frame) = decode(&bytes) {
|
||||
assert!(frame.payload.len() <= MAX_PAYLOAD_BYTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_frames_round_trip_at_payload_boundaries() {
|
||||
for size in [0, 1, 4_095, MAX_PAYLOAD_BYTES] {
|
||||
let frame = Frame {
|
||||
class: TrafficClass::Bulk,
|
||||
service: ServiceId(42),
|
||||
payload: vec![0xab; size],
|
||||
};
|
||||
let bytes = encode(&frame).expect("boundary frame encodes");
|
||||
assert_eq!(decode(&bytes), Ok(frame));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_headers_and_trailing_bytes_are_rejected() {
|
||||
let frame = Frame {
|
||||
class: TrafficClass::Text,
|
||||
service: ServiceId(7),
|
||||
payload: b"hello".to_vec(),
|
||||
};
|
||||
let valid = encode(&frame).expect("frame");
|
||||
let mut bad_magic = valid.clone();
|
||||
bad_magic[0] = b'X';
|
||||
assert_eq!(decode(&bad_magic), Err(FrameError::InvalidHeader));
|
||||
|
||||
let mut bad_version = valid.clone();
|
||||
bad_version[2] = 99;
|
||||
assert_eq!(decode(&bad_version), Err(FrameError::InvalidHeader));
|
||||
|
||||
let mut trailing = valid;
|
||||
trailing.push(0);
|
||||
assert_eq!(decode(&trailing), Err(FrameError::TrailingBytes));
|
||||
}
|
||||
|
||||
fn next(state: u64) -> u64 {
|
||||
state
|
||||
.wrapping_mul(6_364_136_223_846_793_005)
|
||||
.wrapping_add(1_442_695_040_888_963_407)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue