1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Fix substraction underflow with IL sequence

The IL escape sequence (CSI Ps L) allows inserting blank, uninitialized
lines. `Ps` is a placeholder for the number of lines that should be
inserted. Before this change Alacritty would crash when a large number
of lines was passed as `Ps` parameter.

The issue was caused whenever the current line of the cursor plus the
lines that should be inserted would leave the bottom of the terminal,
since this makes indexing impossible.

This patch makes sure that the biggest amount of lines inserted does
never exceed the end of the visible region minus the current line of the
curser, which fixes the underflow issue.

This fixes #1515.
This commit is contained in:
Christian Duerr 2018-09-05 21:15:16 +00:00 committed by GitHub
parent 72495172c2
commit 43882ade33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1209,9 +1209,10 @@ impl Term {
/// Text moves down; clear at bottom /// Text moves down; clear at bottom
/// Expects origin to be in scroll range. /// Expects origin to be in scroll range.
#[inline] #[inline]
fn scroll_down_relative(&mut self, origin: Line, lines: Line) { fn scroll_down_relative(&mut self, origin: Line, mut lines: Line) {
trace!("scroll_down_relative: origin={}, lines={}", origin, lines); trace!("scroll_down_relative: origin={}, lines={}", origin, lines);
let lines = min(lines, self.scroll_region.end - self.scroll_region.start); lines = min(lines, self.scroll_region.end - self.scroll_region.start);
lines = min(lines, self.scroll_region.end - origin);
// Scroll between origin and bottom // Scroll between origin and bottom
self.grid.scroll_down(&(origin..self.scroll_region.end), lines, &self.cursor.template); self.grid.scroll_down(&(origin..self.scroll_region.end), lines, &self.cursor.template);