Skip to content

TEST-001: Adicionar fuzz testing com cargo-fuzz para WAL, SSTable e API #371

@ElioNeto

Description

@ElioNeto

🟡 Médio | Qualidade | Testes

Problema

Não há fuzz testing no projeto. Entradas maliciosas ou corrompidas (WAL frames, SSTable bytes, requisições HTTP) podem causar panics ou comportamentos inesperados que testes unitários não cobrem.

Impacto

  • Vulnerabilidades de segurança podem passar despercebidas
  • Crash em produção por dados corrompidos
  • Sem cobertura de edge cases extremos

Evidência

Nenhum target de cargo-fuzz no projeto.
src/infra/scrubber.rs: testa CRC32 mas sem fuzzing de bytes aleatórios.

Correção recomendada

Adicionar 3 targets de fuzz:

  1. WAL Frame Fuzzing (fuzz_targets/wal_frame.rs):
#![no_main]
use libfuzzer_sys::fuzz_target;
use apexstore::storage::wal::WriteAheadLog;

fuzz_target!(|data: &[u8]| {
    // Simular replay de WAL com dados corrompidos
    // Verificar que não há panic
    let dir = tempfile::tempdir().unwrap();
    let wal_path = dir.path().join("fuzz.wal");
    std::fs::write(&wal_path, data).unwrap();
    let _ = WriteAheadLog::recover(&wal_path);
});
  1. SSTable Fuzzing (fuzz_targets/sstable.rs):
fuzz_target!(|data: &[u8]| {
    // Tentar abrir SSTable com bytes aleatórios
    // Verificar que não há panic (apenas erro graceful)
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("fuzz.sst");
    std::fs::write(&path, data).unwrap();
    let _ = SstableReader::open(&path, NoopCache);
});
  1. API Input Fuzzing (fuzz_targets/api_input.rs):
fuzz_target!(|data: &[u8]| {
    // Tentar processar JSON malformado como requisição
    let _: Result<SetBody, _> = serde_json::from_slice(data);
});

Setup:

cargo install cargo-fuzz
cargo fuzz init
cargo fuzz add wal_frame
cargo fuzz add sstable
cargo fuzz add api_input

Esforço: Médio (8h)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions