Metadata-Version: 2.5
Name: stitch-fuzz
Version: 0.2.0
Summary: STITCH++: API fuzzing for C/C++, Objective-C, Python, JavaScript, Java, Go, Rust, Ruby and Swift libraries, built for coding agents
Project-URL: Homepage, https://github.com/hgarrereyn/STITCHplusplus
License: MIT
License-File: LICENSE
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# STITCH++

Write small typed stubs defining your API. STITCH++ automatically fuzzes valid combinations of
endpoints, generates arguments, and finds crashes, exceptions, and failed checks.

> [!NOTE]
> **Are you an agent?** Read this instead:
> https://hgarrereyn.github.io/STITCHplusplus/agents/overview.raw.md

**[Documentation](https://hgarrereyn.github.io/STITCHplusplus/)** ·
[Tutorial](https://hgarrereyn.github.io/STITCHplusplus/guide/tutorial/library/) ·
[CLI reference](https://hgarrereyn.github.io/STITCHplusplus/reference/cli/) ·
[Example projects](projects/README.md) ·
[Paper](https://doi.org/10.1145/3830454.3846663)

## How it works

A harness is a set of **endpoints**: small typed stubs that each call your API.

```cpp
STITCH_OBJECT(Store, kv_store*);
STITCH_OBJECT(Snapshot, kv_store*);

New<Store> load(Str<256> text) {
    kv_store* st = kv_load(text.c_str());
    stitch::require(st, "invalid text");
    return st;
}
STITCH_ENDPOINT(load);

void put(Borrow<Store> st, Str<16> key, Str<32> value) {
    stitch::require(kv_put(st, key.c_str(), value.c_str()) == 0, "invalid key or value");
}
STITCH_ENDPOINT(put);

void remove_key(Borrow<Store> st, Str<16> key) { kv_remove(st, key.c_str()); }
STITCH_ENDPOINT(remove_key);

New<Snapshot> snapshot(Borrow<Store> st) {
    char* text = kv_dump(st);
    kv_store* copy = kv_load(text);
    free(text);
    stitch::require(copy, "dump did not load");
    return copy;
}
STITCH_ENDPOINT(snapshot);
```

- **Objects** (`Store`, `Snapshot`) pass from one call to the next. `New<T>` makes one, `Borrow<T>`
  uses it, `Take<T>` consumes it.
- **Fuzzed parameters** (`Str<16>`, integers, bytes) are generated by the fuzzer.
- `require` rejects an input. `check` asserts a property; a failed check is reported as a bug.

The fuzzer **stitches** endpoints into programs, keeps the ones that reach new code, and mutates
both the arguments and the calls. A crash it found, minimized:

```
st = load("")
put(st, "tmp", "")
remove_key(st, "tmp")
snapshot(st)   // AddressSanitizer: heap-use-after-free in kv_dump
```

## Install

```sh
pip install stitch-fuzz
stitch setup --lang python
```

Requires Docker. The library, the harness and the fuzzer run in containers.

A project pins the STITCH++ release it is written for in its `stitch.toml`
(`stitch_version = "0.2.0"`); install that version to work on it. What changed between releases,
and what a harness has to change to upgrade: [CHANGELOG.md](CHANGELOG.md).

## Languages

[C/C++](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/cpp/) ·
[Python](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/python/) ·
[JavaScript](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/javascript/) ·
[Java](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/java/) ·
[Go](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/go/) ·
[Rust](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/rust/) ·
[Ruby](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/ruby/) ·
[Swift](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/swift/) ·
[Objective-C](https://hgarrereyn.github.io/STITCHplusplus/reference/languages/objc/)

<details>
<summary>How each language is instrumented</summary>

| Language | Coverage | Comparisons (cmplog) | Bugs detected |
|---|---|---|---|
| C/C++ | SanitizerCoverage (clang) | `trace-cmp`, `memcmp`/`strcmp` hooks | ASan, UBSan, uncaught exceptions |
| Python | `sys.monitoring` line and branch events | AST rewrite of `==`, `!=`, `in`, `<` | undeclared exceptions |
| JavaScript | Babel plugin (CommonJS hook and ESM loader) | Babel rewrite of `===` and `switch`; `String`/`Set`/`Map` hooks | undeclared exceptions, prototype pollution, unhandled rejections |
| Java | Java agent, counters per basic block | `if_icmp`, `lcmp`, `switch`, `String.equals`/`startsWith`, `Map.get` | undeclared `Throwable`s |
| Go | `-d=libfuzzer` 8-bit counters | `libfuzzerTraceCmp*`, `libfuzzerHookStrCmp` | panics, fatal errors, data races (`-race`, optional) |
| Rust | SanitizerCoverage | `trace-compares`, ASan `memcmp` hooks | panics (including overflow checks), ASan |
| Ruby | Prism source rewriting | rewritten `==`, `<`, `eql?`, `start_with?`, `include?`, `case`/`when` | undeclared exceptions |
| Swift | SanitizerCoverage | `trace-cmp` | traps (bounds, overflow, nil unwrap), ASan |
| Objective-C | SanitizerCoverage (clang, GNUstep) | `trace-cmp`, `memcmp`/`strcmp` hooks, `NSString` comparison wrappers | Objective-C exceptions, ASan, UBSan |

In every language, failed `check`s in your stubs and timeouts are reported too. Details:
[`languages/README.md`](languages/README.md).

</details>

## Citation

```bibtex
@inproceedings{green2026stitching,
  title     = {Automatic, Expressive, and Scalable Fuzzing with Stitching},
  author    = {Green, Harrison and Brown, Fraser and Le Goues, Claire},
  booktitle = {Proceedings of the 2026 ACM SIGSAC Conference on Computer and Communications Security},
  series    = {CCS '26},
  publisher = {ACM},
  address   = {The Hague, Netherlands},
  pages     = {1582--1596},
  year      = {2026},
  doi       = {10.1145/3830454.3846663}
}
```

## License

[MIT](LICENSE)
