Skip to content

Commit

Permalink
Kill previewer child process and don't output invalid utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
natecraddock committed Sep 24, 2024
1 parent b57fec8 commit 0e42160
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Previewer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ fn threadLoop(previewer: *Previewer, loop: *vaxis.Loop(Event)) !void {
});
defer poller.deinit();

const max_output_bytes = 4096 * 10;
const max_output_bytes = 4096 * 4;
while (try poller.poll()) {
if (poller.fifo(.stdout).count > max_output_bytes) break;
if (poller.fifo(.stderr).count > max_output_bytes) break;
}
_ = try child.wait();
_ = try child.kill();

// Because zf uses an arena allocator for everything, this could possibly grow to
// use a lot of memory. But zf is a short-lived process so this should be fine.
Expand All @@ -95,6 +95,10 @@ fn threadLoop(previewer: *Previewer, loop: *vaxis.Loop(Event)) !void {
previewer.output = try poller.fifo(.stdout).toOwnedSlice();
}

if (!std.unicode.utf8ValidateSlice(previewer.output)) {
previewer.output = "Invalid utf8";
}

previewer.last_arg = try allocator.dupe(u8, previewer.arg);
loop.postEvent(.preview_ready);
}
Expand Down

0 comments on commit 0e42160

Please sign in to comment.