Skip to content

Overview

STITCH++ finds bugs in libraries by calling their API with generated inputs. It supports C/C++, Python, JavaScript, Java, Go, Rust, Ruby, Swift and Objective-C, and works the same way in each.

You write stubs: small typed functions that each make one API call.

@stitch.endpoint(bails_on=(ValueError,))
def load(text: Str[256]) -> New[Store]:
return kvlib.load(text)
@stitch.endpoint
def remove(st: Borrow[Store], key: Str[16]):
st.remove(key)
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 remove_key(Borrow<Store> st, Str<16> key) { kv_remove(st, key.c_str()); }
STITCH_ENDPOINT(remove_key);
stitch.endpoint("load", { text: Str(256) }, New(Store), ({ text }) => kv.load(text),
{ bailsOn: [RangeError] });
stitch.endpoint("remove", { st: Borrow(Store), key: Str(16) }, null, ({ st, key }) => st.remove(key));
@Endpoint(bailsOn = {IllegalArgumentException.class})
public static Store load(@Str(max = 256) String text) {
return Store.load(text);
}
@Endpoint
public static void remove(Store st, @Str(max = 16) String key) {
st.remove(key);
}
stitch.Endpoint("load", kvgo.Load, "text:max=256")
stitch.Endpoint("remove", remove, "st", "key:max=16")
func remove(st *kvgo.Store, key string) { st.Remove(key) }
endpoint! {
fn load(text: Str<256>) -> Result<New<Store>, String> {
Ok(New::new(kvrs::load(&text)?))
}
}
endpoint! {
fn remove(st: Borrow<Store>, key: Str<16>) {
st.remove(&key);
}
}
Stitch.endpoint :load, { text: Str[256] }, New[Store], bails_on: [ArgumentError] do |text|
Kvrb.load(text)
end
Stitch.endpoint :remove, { st: Borrow[Store], key: Str[16] } do |st, key|
st.remove(key)
end
let load = endpoint("load") { (text: Str<256, Plain>) throws -> New<Store> in
New(try KVSwift.load(text.value))
}
let remove = endpoint("remove") { (st: Borrow<Store>, key: Str<16, Plain>) in
st.value.remove(key.value)
}
STITCH_ENDPOINT(New(Store), load, Str(256) text) {
KVStore *st = [KVStore storeWithText:text error:NULL];
STRequire(st != nil, @"invalid text");
return st;
}
STITCH_ENDPOINT(void, remove, Borrow(Store) st, Str(16) key) {
[st removeKey:key];
}

The fuzzer stitches stubs into programs: it creates a store with load, removes a key from that store, and so on. It generates the arguments, keeps the programs that reach new code, and mutates them: changing arguments, and inserting, deleting and rewiring calls.

It reports:

  • crashes and sanitizer reports (ASan, UBSan)
  • panics, traps and exceptions your stubs did not declare
  • failed checks: properties you assert, such as “dump then load gives the same store”
  • programs that run past a timeout

For each bug, STITCH++ shows the calls that led to it, minimizes the program, and writes it as a standalone reproducer.

  • Docker with buildx
  • Python 3.9 or newer, for the stitch command

The library, the harness and the fuzzer all build and run in Docker. You don’t need the language’s toolchain on your machine.

  • Install the stitch command.
  • Follow the tutorial. It fuzzes a small key-value store in the language you pick, from a new project to a minimized reproducer.
  • Concepts explains objects, parameters, data types and attributes in more depth.
  • The CLI reference lists every command.