Skip to content

Evaluate and implement fuzzing tests #106

@unclesp1d3r

Description

@unclesp1d3r

Summary

Evaluate whether dedicated fuzzing tests (e.g., cargo-fuzz / libFuzzer) are appropriate for the project, and implement them if so. v0.3.0 introduces features with significantly more complex parsing and evaluation paths that would benefit from coverage-guided fuzzing.

Current State

  • unsafe_code = "forbid" is enforced project-wide, so memory corruption is not a concern
  • Property tests via proptest (tests/property_tests.rs) generate random inputs for the parser and evaluator, providing a lightweight form of fuzzing
  • 94%+ line coverage with 1,000+ tests across unit, integration, property, and doc tests
  • Attack surface is currently small: 4 types, 7 operators, absolute/from-end offsets

v0.3.0 Features That Would Benefit

These features introduce complex, data-dependent parsing and evaluation paths where edge cases are hard to enumerate manually:

  • Regex type (regex/N): Pattern compilation from untrusted magic files, binary-safe matching against arbitrary file content. Malformed patterns, catastrophic backtracking, and binary edge cases are classic fuzzing targets.
  • 64-bit integer types (quad, bequad, lequad): Wider value ranges increase the combinatorial space for comparison and bitwise operators.
  • Floating-point types (float, double, befloat, lefloat): NaN, infinity, subnormals, and endianness handling create subtle edge cases.
  • Search type: Variable-length pattern matching with offset ranges.

Suggested Fuzz Targets

  1. Parser fuzzing: Feed random bytes as magic file content to the parser; verify it never panics
  2. Evaluator fuzzing: Generate random (rule, buffer) pairs; verify evaluation never panics
  3. End-to-end fuzzing: Random magic file + random target buffer through MagicDatabase::evaluate_buffer

Evaluation Criteria

  • Does cargo-fuzz find bugs that proptest misses?
  • Is the maintenance overhead (fuzz corpus, CI integration) justified?
  • Does this contribute to OSSF Best Practices silver/gold badge requirements?

Acceptance Criteria

  • Document evaluation decision (proceed or defer with rationale)
  • If proceeding: fuzz/ directory with at least parser and evaluator targets
  • If proceeding: CI job for scheduled fuzzing runs (not per-PR, too slow)
  • If proceeding: Initial corpus seeded from existing test fixtures and src/builtin_rules.magic

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmemory-safetyMemory safety improvements and guaranteessize:MThis PR changes 30-99 lines, ignoring generated files.testingTest infrastructure and coverage

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions