Skip to content

Commit 08e2649

Browse files
committed
Add heap fallback for HTML formatter buffer in scanHyperlinks
The hyperlink scanner uses a fixed 256KB stack buffer for HTML formatter output. For very large terminals this could silently drop all hyperlink detection. Fall back to a 1MiB heap allocation when the stack buffer is insufficient.
1 parent 04ca152 commit 08e2649

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/render.zig

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,21 @@ fn scanHyperlinks(
247247
}
248248
defer gt.c.ghostty_formatter_free(formatter);
249249

250-
// Format into a stack buffer
250+
// Format into a stack buffer; fall back to heap if too small
251251
var html_buf: [262144]u8 = undefined;
252252
var out_len: usize = 0;
253-
if (gt.c.ghostty_formatter_format_buf(formatter, &html_buf, html_buf.len, &out_len) != gt.SUCCESS) {
254-
return .{ .count = 0, .uri_used = 0 };
253+
if (gt.c.ghostty_formatter_format_buf(formatter, &html_buf, html_buf.len, &out_len) == gt.SUCCESS) {
254+
return parseHtmlHyperlinks(html_buf[0..out_len], spans, uri_buf);
255255
}
256256

257-
return parseHtmlHyperlinks(html_buf[0..out_len], spans, uri_buf);
257+
const heap_buf = std.heap.page_allocator.alloc(u8, 1024 * 1024) catch {
258+
return .{ .count = 0, .uri_used = 0 };
259+
};
260+
defer std.heap.page_allocator.free(heap_buf);
261+
if (gt.c.ghostty_formatter_format_buf(formatter, heap_buf.ptr, heap_buf.len, &out_len) != gt.SUCCESS) {
262+
return .{ .count = 0, .uri_used = 0 };
263+
}
264+
return parseHtmlHyperlinks(heap_buf[0..out_len], spans, uri_buf);
258265
}
259266

260267
/// Parse HTML output to extract hyperlink spans and their URIs.

0 commit comments

Comments
 (0)