Hunt for bugs: automated bug finding with symbolic execution
osprey hunt searches for failing inputs using KLEE symbolic execution. It solves path constraints within a time budget; fuzzers explore concrete inputs. Both approaches complement tests and static analysis.
Inspect each finding's verdict: a reproduced crash failed in a native replay; an unmodelled operation records an engine limitation. An empty report is not a correctness proof.
osprey hunt accepts a Default, ML or Python-flavor source file, a project directory or an osprey.toml manifest. Python-flavor files carry # osprey: flavor=python.
Run your first hunt
On macOS or Linux x86_64, install KLEE through Homebrew, then build Osprey from the repository root so the symbolic runtime is available:
brew install klee
make build
./target/release/osprey hunt src/osprey/tests/hunt/crash.osp --input-bytes 1 --max-time 10
This example deliberately calls C abort() only when its input is "9". Hunt discovers that input, reports abort crash.osp:4, and confirms reproduced (SIGABRT) in a normal run. Exit status 1 is expected. process.osp separately tests an unsupported engine operation; it is not the crash demo.
For a clean control, run:
./target/release/osprey hunt src/osprey/tests/hunt/clean.osp --input-bytes 2 --max-time 30
The clean control parses stdin as an integer and safely selects a list element, with fallbacks for invalid input and an out-of-range index. It expects findings: none; a run can still exhaust its budget. An incomplete section means paths stopped at an engine limit or budget, not that a bug was found. The former crash example, src/osprey/tests/hunt/record_update_list.osp, is fixed and also expects no findings.
For your own project:
osprey hunt ./my-project --max-time 60 --input-bytes 4
Each extra symbolic byte can introduce more branches, so start with a small bound and increase it to reach longer inputs. Keep tests that check expected results: Hunt searches for failures, not whether the program does what you intended.
Open the report
Hunt saves HTML and JSON and prints their paths. Open report.html to inspect source excerpts, inputs, replay verdicts and unfinished paths.
Expand For AI to copy the full investigation context: findings, replay details, exact engine arguments, raw diagnostics, source text and analysis limits. The report works offline without JavaScript. It contains local paths and source contents; review it before sharing.
Reports normally live under target/hunt/<program-and-run-id>/. Use --out ./hunt-results for a predictable directory that also keeps raw KLEE artifacts.
Understand the path counts
Paths are different possible executions. The crash demo explores four: three finish normally and one reaches the reproduced abort. None are unfinished; the three normal exits are not missed detections.
| Count | Meaning |
|---|---|
| Paths explored | Different executions reached by the symbolic engine, including paths that fail or stop early. |
| Normal exits | Paths that reached ordinary program completion. A detected crash is excluded from this count. |
| Crashes reproduced | Deduplicated findings that also caused a signal in a normal native run. |
| Unfinished | Paths stopped by an analysis limit, solver failure or engine interruption. Their behavior beyond that point was not checked. |
Findings are deduplicated by failure class and source location, so their count need not equal the number of failing paths. An unsupported operation is an engine limitation, not a demonstrated bug. Never calculate a detection success rate by dividing normal exits by explored paths.
Read a finding
Each finding includes its class, Osprey source location when available, runtime frame, concrete stdin and file bytes, and a replay verdict.
| Report | What to do |
|---|---|
reproduced |
The native build also died from a signal. Keep the input and add a regression test before fixing the defect. |
klee-only |
The native build ran without that crash. Investigate the symbolic runtime model and the input; native replay currently restores stdin and files, not entropy or clock values. |
unmodelled |
The program reached an operation the symbolic runtime cannot model. This is a coverage boundary; native replay skips it. |
skipped or not run |
Read the reason, or rerun with native replay enabled. There is no native reproduction verdict yet. |
incomplete |
Some paths hit time, memory or solver limits. Adjust the budget or reduce the input bound. |
A memory-safety failure outside deliberate or unsafe C-boundary misuse points to a compiler, runtime or symbolic-model defect. Keep the reported source location and input when reporting it.
Options and automation
osprey hunt ./my-project --json --quiet --max-time 60 > hunt.json
osprey hunt ./my-project --out ./hunt-results --input-bytes 4
| Option | Default and behavior |
|---|---|
--max-time <seconds> |
60 seconds; positive whole number. |
--max-memory <mb> |
2000 MB; minimum 256 MB. |
--input-bytes <n> |
64 bytes per symbolic stream; accepts 0–4096. |
--out <dir> |
Save both reports and keep KLEE artifacts, including concrete .ktest inputs. Otherwise raw temporary output is deleted after the report context is captured. An unrelated non-empty directory is refused. |
--json |
Also write JSON to stdout for automation; saved reports remain enabled. |
--no-html |
Disable the saved HTML report. |
--no-json |
Disable the saved JSON report; an explicit --json still writes JSON to stdout. |
--quiet |
Suppress progress on stderr. |
--no-replay |
Skip the native build and replay; any finding then makes the command fail. |
Exit status is 0 when there is no failing finding, 1 for a native reproduction, any finding with replay disabled, or a compilation failure, and 2 for usage or toolchain errors. Skipped findings and incomplete paths can coexist with status 0; automation that needs full exploration must inspect the report as well as the exit code.
From the repository, make -C src/osprey/tests/hunt hunt FILE=src/osprey/tests/hunt/crash.osp HUNT_ARGS="--input-bytes 1 --max-time 10" builds the prerequisites and wraps a single run. make -C src/osprey/tests/hunt hunt-corpus sweeps the whole corpus with scripts/hunt, an Osprey app, into target/hunt/report.html; it is not currently a required CI check.
Verify deliberate crash detection
make -C src/osprey/tests/hunt hunt-crashes
The gate covers fifteen planted input cases: stdin, parsing, checked arithmetic, lists, maps, closures, recursion, unions, record invariants, JSON, file input, invalid C free, C double free, ML flavor and Python flavor. Each runs independently within ten seconds. Every expected class, source location, concrete input, file payload and native signal must match. Each case must also have a normal symbolic path, and benign stdin Z must finish normally with the exact expected output. Missing findings, unfinished analysis, tool errors, skipped replay and KLEE-only findings fail the gate.
These tests deliberately violate application invariants or the unsafe C boundary. They demonstrate detection of known failures; they are not new compiler defects. CI runs only the mock/runtime tooling tests (make _test_hunt_mock) in the required C-runtime job. The real KLEE/native-replay crash gate runs by hand (make -C src/osprey/tests/hunt hunt-crashes) until issues #306 and #307 are fixed. A missing engine fails the crash gate rather than skipping it.
Use it in VSCode
Open an .osp or .ospml file and select Osprey: Hunt for Bugs from the command palette or editor context menu. The extension saves the file, runs the compiler selected by the language server, and shows findings in the Osprey Hunt output channel and editor diagnostics. Set osprey.hunt.maxTime to change its time budget.
A reproduced finding is an error, an unreplayed or KLEE-only finding is a warning, and an unmodelled operation is information.
Current boundaries
KLEE runs natively on macOS and Linux x86_64. Linux arm64 and Windows are not supported by the current workflow. If the engine or runtime bitcode is missing, Hunt exits with a setup error. OSPREY_KLEE selects the engine binary and OSPREY_KLEE_RUNTIME selects the runtime bitcode.
Hunt starts at the program entry point; typed function harnesses and automatic regression-test generation are planned. Fibers and resumable control effects use threads that this symbolic model cannot follow. A dynamic control handler can stop exploration at the region entry (__osprey_coro_new), before the input-processing code runs. Use static handlers in a hunt driver where applicable; an unmodelled region has not been checked. Native replay has a 30-second timeout and skips runs that do not exit. Floating-point execution is concretized by KLEE, so numerical code still needs explicit edge cases and oracle comparisons.
See the symbolic execution contract for runtime models, replay details and delivery status.