This guide covers the technical details for developing pickle-fuzzer.
- Rust 1.70 or later
- Python 3.11.x (for Python bindings)
- Git
git clone https://github.com/cisco-ai-defense/pickle-fuzzer
cd pickle-fuzzer
cargo build# Debug build (faster compilation, slower runtime)
cargo build
# Release build (slower compilation, optimized runtime)
cargo build --release
# With Python bindings
cargo build --features python-bindings# Run from source
cargo run -- output.pkl
# Run release binary
cargo run --release -- output.pkl
# Run with arguments
cargo run -- --dir samples --samples 100 --protocol 3pickle-fuzzer/
├── src/
│ ├── lib.rs # Library root and public API
│ ├── main.rs # CLI entry point
│ ├── cli.rs # Command-line argument parsing
│ ├── generator/ # Core generation logic
│ │ ├── mod.rs # Generator struct and public API
│ │ ├── core.rs # Main generation algorithm
│ │ ├── emission.rs # Opcode emission and encoding
│ │ ├── stack_ops.rs # Stack simulation
│ │ ├── validation.rs # Opcode validation
│ │ └── mutation.rs # Mutation orchestration
│ ├── mutators/ # Mutation strategies
│ │ ├── mod.rs # Mutator trait and registry
│ │ ├── bitflip.rs # Bit flip mutations
│ │ ├── boundary.rs # Boundary value mutations
│ │ └── ...
│ ├── opcodes.rs # Opcode definitions and protocol mappings
│ ├── protocol.rs # Protocol version enum
│ ├── stack.rs # Stack object types
│ ├── state.rs # Generator state management
│ └── python.rs # Python bindings (PyO3)
├── tests/ # Integration tests
├── benches/ # Performance benchmarks
├── fuzz/ # Fuzzing targets (cargo-fuzz)
└── python/ # Python package
├── pickle_fuzzer/
│ ├── __init__.py # Python module entry point
│ └── fuzzer.py # Atheris integration
├── examples/ # Python usage examples
└── tests/ # Python tests
Add unit tests at the bottom of source files:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_my_feature() {
let result = my_function();
assert_eq!(result, expected_value);
}
#[test]
fn test_error_case() {
let result = my_function_with_error();
assert!(result.is_err());
}
}Add integration tests in tests/ directory:
use pickle_fuzzer::{Generator, Version};
#[test]
fn test_integration_scenario() {
let mut gen = Generator::new(Version::V3);
let pickle = gen.generate();
assert!(!pickle.is_empty());
assert_eq!(pickle[pickle.len() - 1], b'.'); // Ends with STOP
}# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_name
# Run tests for specific module
cargo test generator::
# Run doc tests only
cargo test --docSee TESTING.md for comprehensive testing guidelines including coverage, validation, and performance testing.
We use rustfmt with default settings:
# Format all code
cargo fmt
# Check formatting without modifying
cargo fmt -- --checkWe use clippy with strict warnings:
# Run clippy
cargo clippy
# Treat warnings as errors (CI requirement)
cargo clippy -- -D warnings
# Fix auto-fixable issues
cargo clippy --fixBefore committing, run:
cargo fmt && cargo clippy -- -D warnings && cargo testWe maintain >70% code coverage:
# Install tarpaulin (first time only)
cargo install cargo-tarpaulin
# Generate coverage report
cargo tarpaulin --out Html --output-dir coverage
# View report
open coverage/tarpaulin-report.html # macOS
xdg-open coverage/tarpaulin-report.html # LinuxCoverage Requirements:
- Overall coverage: >70%
- New code: >80%
- All public APIs must be tested
- Include both unit and integration tests
cd python
python3.11 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install maturin# Development build (editable install)
maturin develop
# Release build
maturin develop --release
# Build wheel
maturin build --release -o dist/cd python
pytest tests/# Run all benchmarks
cargo bench
# Run specific benchmark
cargo bench single_generation
# Generate detailed reports
cargo bench -- --save-baseline my-baseline# Open HTML report
open target/criterion/report/index.htmlSee BENCHMARKS.md for detailed performance analysis.
Add debug output:
dbg!(variable);
eprintln!("Debug: {:?}", value);# Build with debug symbols
cargo build
# Run with lldb (macOS) or gdb (Linux)
rust-lldb target/debug/pickle-fuzzer# Install flamegraph
cargo install flamegraph
# Generate flamegraph
cargo flamegraph -- --dir samples --samples 1000- Add opcode to
src/opcodes.rs - Add to protocol version map
- Implement stack effects in
src/generator/stack_ops.rs - Add emission logic in
src/generator/emission.rs - Add validation rules in
src/generator/validation.rs - Add tests
- Create file in
src/mutators/ - Implement
Mutatortrait - Add to
MutatorKindenum insrc/mutators/mod.rs - Add tests
- Update documentation
# Check for outdated dependencies
cargo outdated
# Update dependencies
cargo update
# Update to latest compatible versions
cargo upgrade # Requires cargo-editOur CI pipeline runs:
- Formatting check:
cargo fmt -- --check - Linting:
cargo clippy -- -D warnings - Tests:
cargo test --all - Coverage:
cargo tarpaulin - Benchmarks:
cargo bench(on main branch) - Fuzzing:
cargo fuzz(nightly)
Ensure all checks pass locally before pushing.
- Update version in
Cargo.tomlandpyproject.toml - Update
CHANGELOG.md - Run full test suite
- Create git tag:
git tag -a vX.Y.Z -m "Release vX.Y.Z" - Push tag:
git push origin vX.Y.Z - The GitHub release workflow will create or update the GitHub Release, build release binaries, attach checksums, and publish build attestations
- Documentation: Check inline docs with
cargo doc --open - Examples: See
examples/directory - Discussions: GitHub Discussions
- Issues: GitHub Issues