libghostty: expose the APC max byte limits

This commit is contained in:
Mitchell Hashimoto
2026-04-20 08:56:40 -07:00
parent 0509f00ad2
commit 0069e28cc6
2 changed files with 36 additions and 0 deletions

View File

@@ -573,6 +573,25 @@ typedef enum GHOSTTY_ENUM_TYPED {
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_MEDIUM_SHARED_MEM = 18,
/**
* Set the maximum bytes the APC handler will buffer for all protocols.
* This prevents malicious input from causing unbounded memory allocation.
* A NULL value pointer removes all overrides, reverting to the built-in
* defaults.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_APC_MAX_BYTES = 19,
/**
* Set the maximum bytes the APC handler will buffer for Kitty graphics
* protocol data. A NULL value pointer removes the override, reverting
* to the built-in default.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_APC_MAX_BYTES_KITTY = 20,
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalOption;

View File

@@ -7,6 +7,7 @@ const ZigTerminal = @import("../Terminal.zig");
const Stream = @import("../stream_terminal.zig").Stream;
const ScreenSet = @import("../ScreenSet.zig");
const PageList = @import("../PageList.zig");
const apc = @import("../apc.zig");
const kitty = @import("../kitty/key.zig");
const kitty_gfx_c = @import("kitty_graphics.zig");
const modes = @import("../modes.zig");
@@ -310,6 +311,8 @@ pub const Option = enum(c_int) {
kitty_image_medium_file = 16,
kitty_image_medium_temp_file = 17,
kitty_image_medium_shared_mem = 18,
apc_max_bytes = 19,
apc_max_bytes_kitty = 20,
/// Input type expected for setting the option.
pub fn InType(comptime self: Option) type {
@@ -331,6 +334,7 @@ pub const Option = enum(c_int) {
.kitty_image_medium_temp_file,
.kitty_image_medium_shared_mem,
=> ?*const bool,
.apc_max_bytes, .apc_max_bytes_kitty => ?*const usize,
};
}
};
@@ -425,6 +429,19 @@ fn setTyped(
}
}
},
.apc_max_bytes => {
wrapper.stream.handler.apc_handler.max_bytes = if (value) |ptr|
.initFull(ptr.*)
else
.{};
},
.apc_max_bytes_kitty => {
if (value) |ptr| {
wrapper.stream.handler.apc_handler.max_bytes.put(.kitty, ptr.*);
} else {
wrapper.stream.handler.apc_handler.max_bytes.remove(.kitty);
}
},
}
return .success;
}