test/fuzz-libghostty: basic afl++-based fuzzer for libghostty

This commit is contained in:
Mitchell Hashimoto
2026-02-28 15:17:58 -08:00
parent 25f12080cb
commit adbb432930
6 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
const std = @import("std");
const ghostty_vt = @import("ghostty-vt");
pub export fn ghostty_fuzz_parser(
input_ptr: [*]const u8,
input_len: usize,
) callconv(.c) void {
var p: ghostty_vt.Parser = .init();
defer p.deinit();
for (input_ptr[0..input_len]) |byte| _ = p.next(byte);
}

View File

@@ -0,0 +1,27 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
void ghostty_fuzz_parser(const uint8_t *input, size_t input_len);
int main(int argc, char **argv) {
uint8_t buf[4096];
size_t len = 0;
FILE *f = stdin;
if (argc > 1) {
f = fopen(argv[1], "rb");
if (f == NULL) {
return 0;
}
}
len = fread(buf, 1, sizeof(buf), f);
if (argc > 1) {
fclose(f);
}
ghostty_fuzz_parser(buf, len);
return 0;
}