mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
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:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user