mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-31 20:59:02 +00:00
fuzz: add OSC parser fuzzer
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
const std = @import("std");
|
||||
const ghostty_vt = @import("ghostty-vt");
|
||||
const mem = @import("mem.zig");
|
||||
const Terminal = ghostty_vt.Terminal;
|
||||
const ReadonlyStream = ghostty_vt.ReadonlyStream;
|
||||
|
||||
/// Use a single global allocator for simplicity and to avoid heap
|
||||
/// allocation overhead in the fuzzer. The allocator is backed by a fixed
|
||||
/// buffer, and every fuzz input resets the bump pointer to the start.
|
||||
var fuzz_alloc: FuzzAllocator = .{};
|
||||
var fuzz_alloc: mem.FuzzAllocator(64 * 1024 * 1024) = .{};
|
||||
|
||||
pub export fn zig_fuzz_init() callconv(.c) void {
|
||||
fuzz_alloc.init();
|
||||
@@ -50,29 +51,3 @@ pub export fn zig_fuzz_test(
|
||||
std.debug.panic("next: {}", .{err});
|
||||
}
|
||||
}
|
||||
|
||||
/// Fixed-capacity allocator that avoids heap allocation and gives the
|
||||
/// fuzzer deterministic, bounded memory behaviour. Backed by a single
|
||||
/// fixed buffer; every `reset()` returns the bump pointer to the start
|
||||
/// so the same memory is reused across iterations.
|
||||
const FuzzAllocator = struct {
|
||||
buf: [mem_size]u8 = undefined,
|
||||
state: std.heap.FixedBufferAllocator = undefined,
|
||||
|
||||
/// 64 MiB gives the fuzzer enough headroom to exercise terminal
|
||||
/// resizes, large scrollback, and other allocation-heavy paths
|
||||
/// without running into out-of-memory on every other input.
|
||||
const mem_size = 64 * 1024 * 1024;
|
||||
|
||||
fn init(self: *FuzzAllocator) void {
|
||||
self.state = .init(&self.buf);
|
||||
}
|
||||
|
||||
fn allocator(self: *FuzzAllocator) std.mem.Allocator {
|
||||
return self.state.allocator();
|
||||
}
|
||||
|
||||
fn reset(self: *FuzzAllocator) void {
|
||||
self.state.reset();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user