fix(terminal): properly invalidate over-sized OSCs

The `self.complete = false` here is important so we don't accidentally
dispatch, for example, a hyperlink command with an empty URI.
This commit is contained in:
Qwerasd
2025-02-10 11:49:05 -05:00
parent 09c76d95c7
commit 03fd9a970b

View File

@ -272,6 +272,9 @@ pub const Parser = struct {
// Maximum length of a single OSC command. This is the full OSC command
// sequence length (excluding ESC ]). This is arbitrary, I couldn't find
// any definitive resource on how long this should be.
//
// NOTE: This does mean certain OSC sequences such as OSC 8 (hyperlinks)
// won't work if their parameters are larger than fit in the buffer.
const MAX_BUF = 2048;
pub const State = enum {
@ -425,9 +428,23 @@ pub const Parser = struct {
/// Consume the next character c and advance the parser state.
pub fn next(self: *Parser, c: u8) void {
// If our buffer is full then we're invalid.
// If our buffer is full then we're invalid, so we set our state
// accordingly and indicate the sequence is incomplete so that we
// don't accidentally issue a command when ending.
if (self.buf_idx >= self.buf.len) {
if (self.state != .invalid) {
log.warn(
"OSC sequence too long (> {d}), ignoring. state={}",
.{ self.buf.len, self.state },
);
}
self.state = .invalid;
// We have to do this here because it will never reach the
// switch statement below, since our buf_idx will always be
// too high after this.
self.complete = false;
return;
}