1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 08:25:50 +03:00

Validate scrollback_lines to avoid crashes (#5996)

* Validate scrollback_lines to avoid crashes

I started using wezterm today, and I immediately tried to configure it
to use "infinite scrollback", as I use in iTerm2. From the configuration
I couldn't tell if there was a way to do this, so I just set it to a
really large number, hoping that would work. Interestingly this works
for very large numbers when the config is just being reloaded while the
terminal is running, but if you then try to restart the application it
crashes (tried to allocate like 100PB or something).

I then came across #1342 and thought "that's seems a bit too involved",
and decided that I probably don't need infinite scrollback, but just
kind of a large number. Through fair dice roll I determined `one billion - 1`
will probably suffice.

Now, this might not be the best solution, so I'm happy to get some feedback.
I was also thinking that it would be nice if one could just set it to `0`,
and then the applicatio determines a suitably large number for the amount of
RAM available, but a) I wasn't sure how this would be best implemented in the
confines of the current architecture, and b) I wasn't sure if it would be well
received.

Long story short, happy to hear your feedback.

* simplify slightly

---------

Co-authored-by: Wez Furlong <wez@wezfurlong.org>
This commit is contained in:
x3ro 2024-09-14 20:33:53 +02:00 committed by GitHub
parent 02c6f5d545
commit 6a2e356156
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -185,7 +185,10 @@ pub struct Config {
pub color_schemes: HashMap<String, Palette>,
/// How many lines of scrollback you want to retain
#[dynamic(default = "default_scrollback_lines")]
#[dynamic(
default = "default_scrollback_lines",
validate = "validate_scrollback_lines"
)]
pub scrollback_lines: usize,
/// If no `prog` is specified on the command line, use this
@ -1638,6 +1641,16 @@ fn default_scrollback_lines() -> usize {
3500
}
const MAX_SCROLLBACK_LINES: usize = 999_999_999;
fn validate_scrollback_lines(value: &usize) -> Result<(), String> {
if *value > MAX_SCROLLBACK_LINES {
return Err(format!(
"Illegal value {value} for scrollback_size; it must be <= {MAX_SCROLLBACK_LINES}!"
));
}
Ok(())
}
fn default_initial_rows() -> u16 {
24
}